Build my own Hello World

It's just a personal note.

build a simple TypeScript environment with Docker

What's this?

  • I'll study TypeScript to use in business
  • Since building an environment from scratch, I tried building it with Docker.

What I learned.

Studying Docker

First, I studied basic Docker features and commands using the official tutorial.

I learned that a container is an isolated environment that runs some code.

Docker 概要 — Docker-docs-ja 24.0 ドキュメント

build an environment

Next, I've tried a simple Docker environment for myself.

When searching on the Internet, I found some articles that introduced some tips to build an environment quickly, but it was not my purpose.

To learn Docker, I tried building it from a simple OS image.

This is my Dockerfile. After launching an ubuntu, some command was called to install TypeScript.

FROM ubuntu:latest
WORKDIR /app
RUN apt-get update && \
    apt-get install -y curl && \
    curl -fsSL https://deb.nodesource.com/setup_16.x | bash - && \
    apt-get install -y nodejs && \
    npm install -g typescript
 CMD ["bash"]

Also, I wrote docker-compose.yml to study docker-compose and to simplify the setting of the bind mount.

Because I want to implement TypeScript code on the local host, I wanted to configure the bind mount.

version: '3'

services:
  typescript_environment:
    build:
      context: .
      dockerfile: Dockerfile
    volumes:
      - .:/app
    stdin_open: true
    tty: true

This is my output.

github.com

run the Docker container and run the TypeScript code

when you run this command in the directory that has the docker-compose.yml file, the container runs.

-d is the detach mode, and it make the container run in the background.

$ docker-compose up -d

docker-compose up — Docker-docs-ja 24.0 ドキュメント

This command shows which container is running.

$ docker ps

And, this command executes the container's command, so you can run the bash and operate in the container.

$ docker exec -it ${container ID} bash

Then, I ran the tsc(compile .ts file to .js).

/app# tsc hello.ts

Finally, I ran the .js file. Yes!! I can compile and run the TypeScript code.

/app# node hello.js
hello, TypeScript!

stop and remove a container

This command can remove the container.

$ docker rm ${container ID}

However, you must stop the container before removing it.

$ docker stop ${container ID}

Impression on Implementation

  • I don't know the internal structure of the Docker now.