Docker is an open-source project that automates the deployment of applications inside software containers, by providing an additional layer
of abstraction and automation of operating-system-level virtualization on Linux.
Docker uses resource isolation features of the Linux kernel such as cgroups and kernel namespaces to allow independent "containers"
to run within a single Linux instance, avoiding the overhead of starting virtual machines.
The latest Docker version can be downloaded from:
http://www.docker.com
Docker container
Information
none
Operating system used
Windows Vista Home Premium SP 2
Software prerequisites
Docker on Windows
Procedure
- Install and run a CentOS container, type: docker run -it centos /bin/bash
- i = interactive, t=assign pseudo-tty (aka terminal)
- centos is the image the container will be based on. The container will be running a CentOS.
- Run the application/process. In this example: /bin/bash in CentOS
- A copy of the centos image was not found locally, so it is downloaded (=pulled) from Docker hub (the public Docker registry).
For example: https://registry-1.docker.io/v1/
You can search the Docker Hub, see:
https://registry.hub.docker.com/search?q=centos
- The CentOS base image is comprised of 3 layers: fd429..., 6941bf..., 41459f...
These 3 layers needs to be downloaded.
- Docker hub contains many different centos versions, each with its own tag. If you do not specify a tag in the run command
docker run -it centos:<tag>, Docker will pull the centos image tagged with "latest".
- If you use the run command and do not specify a name, a random name is automatically assigned.
This random name can be found when using the command docker ps -a
To assign a name, type: docker run -it --name mycentos centos /bin/bash
- A super lightweight barebone CentOS is installed. You can type Unix commands, for example:
- Ping Google DNS: ping 8.8.8.8
- Show running processes: ps -elf
- Install vim: yum install -y nano
- Show the content of the hosts file, type: cat /etc/hosts
The hostname "1900fc506c34" is the hosts file matches the PS1 prompt "root@1900fc506c34" which is also our container id.
- Create a test file, type: nano /tmp/test.txt
and enter the text: Hello World
- Stop the container, type: exit
- Check if no containers are running, type: docker ps -a
Our container id "1900fc506c34" is not running.
- Switch to root user, type: sudo su
- Go to the folder /var/lib/docker/aufs/diff/ where all containers are located.
Type: cd /var/lib/docker/aufs/diff/
- Show the content of this folder, type: ls -al
The hostname "1900fc506c34" is the hosts file matches the PS1 prompt "root@1900fc506c34".
- Go to the folder starting with "1900fc506c34".
Type: cd 1900fc506c34...
And show its content, type: ls -al
- The tmp folder will contain the test.txt file created earlier.
- To start this particular container, type: docker start 1900fc506c34
And attach to this container, type: docker attach 1900fc506c34
- You can still access the /tmp/test.txt file, type: cat /tmp/test.txt
- To exit a running container without killing it, press the keys:
CTRL+P followed by CTRL+Q
After pressing these buttons you will return to your Docker host.
Pressing the keys CTRL+C in a running container, is the same as you type: exit.
Both methods will stop the container.
To attach to a running Docker process, type:
docker attach <image id>
Press the Enter key to get the promp back.
|
|