In this exercise, you create a running Docker container from your previously published Docker image.
Run the following commands to remove the local twkoins_webui
images (including tagged versions):
docker rmi -f twkoins_webui
# Windows only
docker rmi -f rotcaus/twkoins_webui:$env:TEAM_NAME
# MacOS only
docker rmi -f rotcaus/twkoins_webui:${TEAM_NAME}
This will prove that we are pulling our published images and not just using our already present local images.
Before we execute our images, check to see if you have running containers:
docker ps
You should not see any running containers yet.
To execute a container from a Docker image, you need to use the docker run command. This will fetch then run the image. You can also fetch the image first using docker pull then run it. Type docker run --help to see available options.
Start the twkoins_webui
container with the following command:
# Windows
docker run -d -p 3004:80 --name twkoins_webui rotcaus/twkoins_webui:$env:TEAM_NAME
# MacOS
docker run -d -p 3004:80 --name twkoins_webui rotcaus/twkoins_webui:${TEAM_NAME}
Verify that the container is up and running:
docker ps
Open a browser to: http://localhost:3004/
Review the options used with docker run:
-d
runs the container in the background (i.e. "detached").-p XXXX:YYYY
maps a host port to the exposed container port so that the service can be accessed using the host address instead of the container's ephemeral address. HereXXXX
is the host port andYYYY
is the container port.--name
is the container name - if we omit the name one will be generated for us (e.g. "admiring_euclid")- The last argument, eg.
twkoins_webui
, is the Docker image name (prefixed with our registry server address)
Tip (optional): When launching multiple instances of the same image you would usually let Docker assign a random ephemeral port and a container name -- this avoids host port collisions and container name conflicts. Use the -P
flag (capital P, without any port numbers) to let Docker assign an ephemeral port. Omit the --name
parameter to let Docker assign a name for you
View the port mapping (format is [container_port] -> [host_ip]:[host_port]
):
docker port twkoins_webui
You can use docker exec
to execute a process within a running container.
Take a peek at the running processes inside the twkoins_webui
container:
docker exec twkoins_webui ps -ef
docker exec -ti twkoins_webui sh -c "top -n 1"
Note: Containers can also be paused/unpaused, stopped/started, restarted, killed, removed, and more. kill is more harsh than stop, where Docker gives the container a grace period (default 10s) to exit.
By looking at the UI, does the app work?
No, it seems to be broken :( :( :(
The logs might give us more info:
docker logs --follow --tail=20 twkoins_webui
# ==> Output:
Redis error { [Error: Redis connection to redis:6379 failed - getaddrinfo ENOTFOUND redis redis:6379]
The problem is that the twkoins_webui
is configured to lookup the redis
service by host name (redis
) and port (6379
) but there is no corresponding redis
service running and no mechanism to do so yet.
We will use Docker Compose in part 2 to bring redis
into our application stack!
For now, ensure that the previous twkoins_webui
is stopped and removed.
docker kill twkoins_webui
docker rm twkoins_webui