October 23, 2018
In this lab you will run a popular, free, lightweight container and explore the basics of how containers work, how the Docker Engine executes and isolates containers from each other.
Highlighted Concepts
Lab: DevOps Docker Beginners Guide
docker container run hello-world
docker image pull alpine
docker image ls
Run a container on Alpine image
docker container run alpine ls -l
When you call run, the Docker client finds the image (alpine in this case), creates the container and then runs a command in that container. When you run docker container run alpine, you provided a command (ls -l), so Docker executed this command inside the container for which you saw the directory listing. After the ls command finished, the container shut down.
Then try
docker container run alpine echo "hello from alpine"
and
docker container run alpine /bin/sh
The shell starts and closes in Alpine, to interact with the Alpine shell, run
docker container run -it alpine /bin/sh
docker container ls
docker container ls -a
Each docker container run command creates an isolated container, which is listed by command docker container ls -a
For example, create a text file in one container
docker container run -it alpine /bin/ash
echo "hello world" > hello.txt
ls
docker container run alpine ls
The text file is missing because the command ls is run in another container (isolation), this feature not only for security, but to test the effects of making application changes. Isolation allows users to quickly create separate, isolated test copies of an application or service and have them run side-by-side without interfering with one another.
To get back to the container that has my ‘hello.txt’ file, first get the Container ID
docker container ls -a
docker container start <container ID>
docker container exec <container ID> ls
Written by Warren who studies distributed systems at George Washington University. You might wanna follow him on Github