SoFunction
Updated on 2025-03-09

Detailed tutorial on deploying and maintaining the docker environment

1. Installation environment instructions

System environment: centos6.6

Service has been applied: haproxy confd   etcd   docker

Host Name

dockerha-152    192.168.36.152    haproxy confd

dockerEtcd-153     192.168.36.153      etcd

dockermain-154    192.168.36.154    docker

2. Install the lazy package and close the conflicting services

The official documentation requires that Linux kernels be at least 3.8 or above, and docker can only run on 64-bit systems. Since RHEL6 and CentOS6 have kernel versions of 2.6, you must first upgrade the kernel.

cd /etc/ 
wget http:///yum/el6/
yum install kernel-ml-aufs kernel-ml-aufs-devel -y

Modify grub's main configuration file /etc/ and set default=0 to indicate that the content under the first title is the kernel launched by default (usually the newly installed kernel is in the first location).

Then restart and restart the system. At this time, your kernel will be successfully upgraded, and the version should be above 3.8.

uname -r 
[root@dockermain-154 shell]# uname -r

3.10.5-3.el6.x86_64

sed -i '/^SELINUX=/c\SELINUX=disabled' /etc/selinux/config
setenforce 0

The docker-io package has been provided in the Fedora EPEL source. Download and install epel:

rpm -ivh /fedora-epel/6/x86_64/ 
sed -i 's/^mirrorlist=https/mirrorlist=http/' /etc//

3. Install components

(1)haproxy confd

Operation on dockerha-152

1、haproxy 

# yum –y install haproxy 

2、confd 

# wget /kelseyhightower/confd/releases/download/v0.6.3/confd-0.6.3-linux-amd64 
# mv confd /usr/local/bin/confd 
# chmod +x /usr/local/bin/confd 
# /usr/local/bin/confd -version 

(2)etcd

Operation on dockerEtcd-153

# mkdir -p /home/install && cd /home/install 
# wget /coreos/etcd/releases/download/v0.4.6/etcd-v0.4. 
# tar -zxvf etcd-v0.4. 
# cd etcd-v0.4.6-linux-amd64 
# cp etcd* /bin/ 
# /bin/etcd -version 
etcd version 0.4.6 

(3)Docker

# yum -y install docker-io 
# service docker start 
# chkconfig docker on 

4. Docker command

(1) View Help

docker COMMAND --help

(2) Search for available environment images

docker search name as example:

[root@dockermain-154 src]# docker search centos
NAME        DESCRIPTION          STARS  OFFICIAL AUTOMATED
centos        The official build of CentOS.     817  [OK]  
ansible/centos7-ansible    Ansible on Centos7        30     [OK]
tutum/centos      Centos image with SSH access. For the root... 13     [OK]
jdeathe/centos-ssh-apache-php  CentOS-6 6.5 x86_64 / Apache / PHP / PHP m... 8     [OK]
blalor/centos      Bare-bones base CentOS 6.5 image    8     [OK]
jprjr/centos-php-fpm                6     [OK]
steeef/graphite-centos    CentOS  with Graphite and Carbon via ng... 6     [OK]
tutum/centos-6.4     DEPRECATED. Use tutum/centos:6.4 instead. ... 5     [OK]
layerworx/centos     A general CentOS 6 image with the EPEL6 an... 2     [OK]
jr42/chef-solo-centos    Official CentOS base images with current c... 1     [OK]
million12/centos-supervisor   Base CentOS-7 with supervisord launcher, h... 1     [OK]
internavenue/centos-percona   Centos-based Percona image.      1     [OK]
jdeathe/centos-ssh     CentOS-6 6.5 x86_64 / EPEL Repo. / OpenSSH... 1     [OK]
jdeathe/centos-ssh-mysql   CentOS-6 6.5 x86_64 / MySQL. Image include... 1     [OK]
yajo/centos-epel     CentOS with EPEL and fully updated    1     [OK]
nimmis/java-centos     This is docker images of CentOS 7 with dif... 0     [OK]
lighthopper/orientdb-centos   A Dockerfile for creating an OrientDB imag... 0     [OK]
bbrietzke/centos-starter   CentOS 7 with EPEL and SupervisorD    0     [OK]
tcnksm/centos-node     Dockerfile for CentOS packaging node   0     [OK]
insaneworks/centos     CentOS 6.5 x86_64 + @update      0     [OK]
snowyday/centos      Provide for emacs and Ricty font on X11 en... 0     [OK]
dmglab/centos      CentOS with superpowers!      0     [OK]
akroh/centos      Centos 6 container that has been updated w... 0     [OK]
timhughes/centos     Centos with systemd installed and running  0     [OK]
solict/provisionous-puppet-centos CentOS provisions with Puppet included   0     [OK]

(3) Download the mirror

Note that the image name must be written in full, which is the name of the NAME column searched with docker search name.

docker pull name As example:

[root@dockermain-154 src]# docker pull jdeathe/centos-ssh-apache-php
Pulling repository jdeathe/centos-ssh-apache-php
........
62203f428b1f: Download complete 
e1812755a4ca: Download complete 
0910edda3736: Download complete 
Status: Downloaded newer image for jdeathe/centos-ssh-apache-php:latest

(4) View installed images

[root@dockermain-154 src]# docker images
REPOSITORY      TAG     IMAGE ID   CREATED    VIRTUAL SIZE
centos       latest    dade6cb4530a  10 days ago   210.1 MB
jdeathe/centos-ssh-apache-php latest    f1a489312a4a  3 months ago  297.7 MB

(5) Run commands in docker container

The docker run command has two parameters, one is the image name and the other is the command to be run in the image. Note: IMAGE=REPOSITORY[:TAG]. If the IMAGE parameter does not specify the mirrored TAG, the default TAG is latest.

[root@dockermain-154 run]# sudo docker run jdeathe/centos-ssh-apache-php echo 'hello world!'
hello world!
[root@dockermain-154 run]# sudo docker run jdeathe/centos-ssh-apache-php hostname
db7e1d2269fb

(6) List containers

View the recently generated container: docker ps -l

View running container: docker ps

 [root@dockermain-154 run]# docker ps -l
CONTAINER ID  IMAGE         COMMAND    CREATED    STATUS      PORTS    NAMES
db7e1d2269fb  jdeathe/centos-ssh-apache-php:latest "hostname"   27 seconds ago  Exited (0) 26 seconds ago      adoring_babbage 

(7) Display container standard output

[root@dockermain-154 run]# docker ps -l
CONTAINER ID  IMAGE         COMMAND    CREATED    STATUS      PORTS    NAMES
db7e1d2269fb  jdeathe/centos-ssh-apache-php:latest "hostname"   27 seconds ago  Exited (0) 26 seconds ago      adoring_babbage  
[root@dockermain-154 run]# docker logs db7e1d2269fb
db7e1d2269fb

(8) Install programs or services in the container

[root@dockermain-154 run]# sudo docker run centos yum install -y httpd
Loaded plugins: fastestmirror
..........

Dependency Installed:

 apr.x86_64 0:1.4.8-3.el7              
 apr-util.x86_64 0:1.5.2-6.el7             
  0:70.0.6-1.          
 httpd-tools.x86_64 0:2.4.6-19.          
  0:2.1.41-2.el7            

Failed:

  httpd.x86_64 0:2.4.6-19.                                           

Complete!

(9) Save changes to the container and generate a new image

docker commit CONTAINERID [REPOSITORY[:TAG]]

The REPOSITORY parameter can be the new image name or the old image name; if it is the same as the old image name and TAG, the old image will be overwritten.

[root@dockermain-154 ~]# docker commit bd7cc4f4ac92 centos:httpd
1e0915f3247b86414ebc11fd994fc6abfb590ff3b1ab890949c845ee88b2d9f4
[root@dockermain-154 ~]# docker images
REPOSITORY      TAG     IMAGE ID   CREATED    VIRTUAL SIZE
centos       httpd    1e0915f3247b  9 seconds ago  320.8 MB
centos       latest    dade6cb4530a  10 days ago   210.1 MB
jdeathe/centos-ssh-apache-php latest    f1a489312a4a  3 months ago  297.7 MB

(10) Stop running container

(11) View container or mirror details

Below is the new container I just saved the commit generated

[root@dockermain-154 ~]# docker inspect 943e45b6e5f3
[{
 "AppArmorProfile": "",
 "Args": [],
 "Config": {
  "AttachStderr": true,
  "AttachStdin": true,
  "AttachStdout": true,
  "Cmd": [
   "/bin/bash"
  ],
  "CpuShares": 0,
  "Cpuset": "",
  "Domainname": "",
  "Entrypoint": null,
  "Env": [
   "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
  ],
  "ExposedPorts": null,
  "Hostname": "943e45b6e5f3",
  "Image": "centos:httpd",
  "MacAddress": "",
  "Memory": 0,
  "MemorySwap": 0,
  "NetworkDisabled": false,
  "OnBuild": null,
  "OpenStdin": true,
  "PortSpecs": null,
  "StdinOnce": true,
  "Tty": true,
  "User": "",
  "Volumes": null,
  "WorkingDir": ""
 },

(12) Delete the container

docker rm CONTAINERID

View all container IDs: docker ps -a -q

Delete all containers: docker rm $(docker ps -a -q)

(13) Delete the mirror

docker rmi IMAGE

(14) Check the docker information, including the number of Containers and Images, kernel version, etc.

[root@dockermain-154 ~]# docker info
Containers: 14
Images: 56
Storage Driver: aufs
 Root Dir: /var/lib/docker/aufs
 Dirs: 89
Execution Driver: native-0.2
Kernel Version: 3.10.5-3.el6.x86_64
Operating System: <unknown>
CPUs: 1
Total Memory: 989.6 MiB
Name: dockermain-154
ID: W4PW:W3XR:FQZE:SBAA:2DS2:BM6N:DV5B:ARF2:3SZM:XGST:5ZF7:DFZV
WARNING: No swap limit support

(15) Create a container and use it like the usual ssh login

[root@dockermain-154 ~]# docker run -i -t centos /bin/bash
[root@7c0414d03fe7 /]# ls
bin dev etc home lib lib64 lost+found media mnt opt proc root run sbin selinux srv sys tmp usr var

The above is a detailed tutorial on deploying and maintaining the docker environment introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to everyone in time. Thank you very much for your support for my website!