Docker Workshop

Make your own image

Prerequisites

  1. Clone this repository git clone https://github.com/bossan/docker-workshop
  2. Go to the folder docker-workshop/examples/dockerfile.

Build an image from the Dockerfile

Run the following command to build an image:

docker build -t workshop-app .

Run the container

Run the following command to start the container:

docker run -d -p 3000:3000 workshop-app

Check running containers

Run the following command:

docker ps

Open the app

Go to http://localhost:3000 to see what the app does.

Using play-with-docker? Instead of opening localhost:3000 you should click on the “OPEN PORT” button and fill in 3000. This should open a new page with the application.

Run even more containers

It is possible to run multiple containers based on the same image. You can use the following command to start another container:

docker run -d -p 3001:3000 --name second-container workshop-app

Stop the running containers

Before we continue to the next step, you should stop all running containers.

First check which containers are running with:

docker ps

This should look something like:

CONTAINER ID   IMAGE            COMMAND                  CREATED          STATUS          PORTS                    NAMES
9123b9d77e25   workshop-app     "docker-entrypoint.s…"   3 seconds ago    Up 2 seconds    0.0.0.0:3001->3000/tcp   second-container
c529fce32424   workshop-app     "docker-entrypoint.s…"   14 seconds ago   Up 13 seconds   0.0.0.0:3000->3000/tcp   dreamy_swirles

Now you can stop each container by specifying the ID:

docker stop c529fce32424

Or

docker stop second-container

Starting containers again

After stopping a container it is not gone. You can restart the container. For example:

docker start second-container

Deleting containers

If you want to delete a container, you can do so with the following command:

docker rm second-container

Note: You cannot delete a running container.