Docker creates an image and runs a container using the image

  1. Create a docker image using the Docker file.
  2. Run a container using the Docker image
  3. Check the logs

Create a docker image using the Docker file.

$ docker build -t <image_name> .

# Sample 
$ docker build -t jayjodev/k8s-node-app .
$ docker image ls
REPOSITORY                           TAG                                              IMAGE ID            CREATED             SIZE
jayjodev/k8s-node-app                latest                                           f2c1a058ede6        3 minutes ago       121MB

Run a container using the Docker image

$ docker run -d --name <container_name> -p 4000:4000 <image_name>

# Sample
$ docker run -d --name k8s-node-app-container -p 4000:4000 jayjodev/k8s-node-app
ef1351929eb92f07480c389cd268957ed6a48f8c3ff2c2c41bd8b6bb79c76c1c

$ docker ps
CONTAINER ID        IMAGE                                 COMMAND                  CREATED             STATUS              PORTS                                                                                                      NAMES
ef1351929eb9        jayjodev/k8s-node-app                 "docker-entrypoint.s…"   2 minutes ago       Up 2 minutes        0.0.0.0:4000->4000/tcp   

Check the logs

$ docker logs -f <container_name>

# Sample
$ docker logs -f k8s-node-app-container

> k8s-service@1.0.0 start
> node index.js

Lunch app is listening on port !4000

Leave a Reply

Your email address will not be published.

ANOTE.DEV