Docker container usage examples in Linux

  
                

In the previous article, we introduced the installation of Docker (see How to install Docker in CentOS 6.5 system). Many friends don't know how to use Docker container after installation. Everyone introduces how Linux uses Docker containers.

1. Start a Docker container

[root @ localhost ~] # docker run -i -t Ubuntu /bin /bash

Unable to find image & lsquo ;ubuntu’ locally

Pulling repository ubuntu

04c5d3b7b065: Download complete

511136ea3c5a: Download complete

c7b7c6419568: Download complete

70c8faa62a44 : Download complete

d735006ad9c1: Download complete

Status: Downloaded newer image for ubuntu:latest

Note:

-i: Open STDIN in the container

-t: Assign a pseudo tty terminal to the container

From the above we can see that Docker will first check if there is a ubuntu image locally. If the image is not found locally, then Docker Go to the official Docker Hub Registry to see if there is this image in the Docker Hub. Once Docker finds the image, it downloads the image and saves it to the local host.

Then, Docker creates a new container with this image inside the file system. The container has its own network, IP address, and a bridged network interface that can be used to communicate with the host. Finally, we tell Docker what commands to run in the new container.

When the container is created, Docker executes the /bin/bash command in the container. At this time we can see the shell inside the container

root@8c342c0c275c:/#

Note: 8c342c0c275c represents the ID of the container

2.Use the container

View the host name of the container

root@8c342c0c275c:/# hostname

8c342c0c275c

As you can see, the host name of the container is the ID of the container

View the host's hosts file

root@8c342c0c275c:/# cat /etc/hosts

172.17.0.2 8c342c0c275c

ff00::0 ip6-mcastprefix< Br>

ff02::1 ip6-allnodes

ff02::2 ip6-allrouters

127.0.0.1 localhost

::1 localhost ip6-localhost ip6- Loopback

fe00::0 ip6-localnet

You can see that Docker has added a host configuration item to the container's IP address.

View the IP address of the container

root@8c342c0c275c:/# ip a

1: lo: "LOOPBACK, UP, LOWER_UP" mtu 65536 qdisc noqueue state UNKNOWN group Default

link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

inet 127.0.0.1/8 scope host lo

valid_lft forever preferred_lft forever

inet6 ::1/128 scope host

valid_lft forever preferred_lft forever

4: eth0: "BROADCAST,UP,LOWER_UP" mtu 1500 qdisc pfifo_fast state UP group default qlen 1000

link/ether 02:42:ac:11:00:02 brd ff:ff:ff:ff:ffp:fp=inp 172.17. 0.2/16 scope global eth0

valid_lft forever preferred_lft forever

inet6 fe80::42:acff:fe11:2/64 scope link

valid_lft forever preferred_lft forever
Previous123Next page Total 3 pages

Copyright © Windows knowledge All Rights Reserved