Using the EC2 container service
We just went over creating a Docker image for our application. Here, we saw how easy and fast it is to start a container using Docker. This is a very transformative experience compared to using only virtual machine technologies such as EC2. One possibility that we haven't explicitly mentioned so far is that you can start multiple containers with the same image. We can, for example, start ourhelloworld
container five times, binding five different ports using the following command (adapt the ID based on the image ID you built. If needed, run Docker imagesto find its ID):
$ for p in {3001..3005}; do docker run -d -p ${p}:3000 4a6cb81d088d; done
We can validate that everything is working using the ps
and curl
commands:
$ docker ps $ curl localhost:3005
The output of running the preceding command is as follows:
Note
Cleaning up containers:
We can clean up everything by stopping and removing all containers with these two handy one-line commands:
$ docker stop $(docker...