1. docker installation
step 1: install the necessary number of system tools
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
Step 2: Add source software information
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
Step 3: update and install Docker-CE
sudo yum makecache fast
sudo yum -y install docker-ce
Step 4: open Docker Service
sudo service docker start
2. docker run container
jenkins
docker run \
--name jenkins\
-d \
--rm \
-u root \
-p 8686:8080 \
-v /data/jenkins/jenkins-data:/var/jenkins_home \
-v /data/jenkins/run/docker.sock:/var/run/docker.sock \
-v /data/jenkins/home:/home \
jenkinsci/blueocean
Note:
-name developing container name
-u root user to specify
-d background
-v volumn mapping host machine path: container path
-p port mapping host machine port: container port
Activemq
docker run --name activemq \
-d\
-v /data/activemq:/data/activemq \
-v /data/activemq/conf:/opt/activemq/conf\
-v /data/activemq/log:/var/log\
-p 61616:61616\
-p 8161:8161\
webcenter/activemq
Zookeeper
docker run \
--name zookeeper \
--hostname zookeeper \
--restart always -d \
-p 2181:2181 -p 2888:2888 -p 3888:3888 \
-v /data/zk/conf:/conf \
-v /data/zk/data:/data \
-v /data/zk/datalog:/datalog \
zookeeper
Mysql
docker run -p 3306:3306 \
--name mysql \
-v $PWD/conf:/etc/mysql/conf.d \
-v $PWD/logs:/logs \
-v $PWD/data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=devuser \
-d mysql:latest
- -p 3306: 3306: 3306 mapped to port 3306 of container port on the computer.
- -v -v $ PWD / conf: /etc/mysql/conf.d: the conf / my.cnf under the current directory is mounted to the host /etc/mysql/my.cnf container.
- -v $ PWD / logs: / logs: the logs directory under the current directory is mounted to the host container / logs.
- -v $ PWD / data: / var / lib / mysql: a data directory of the host current directory is mounted to the container / var / lib / mysql.
- -e MYSQL_ROOT_PASSWORD = 123456: initialize the root user's password.
Redis
docker run --name redis \
-p 6379:6379 \
-v /data/redis/data:/data \
--appendonly yes \
-d redis:3.2
3. docker know how the parameters of the container
When docker run command, you need to pass parameters, and sometimes do not know what parameters Yes.
For example activemq
docker run --name activemq
-d
-v /data/activemq:/data/activemq
-v /data/activemq/conf:/opt/activemq/conf
-v /data/activemq/log:/var/log
-p 61616:61616
-p 8161:8161
webcenter/activemq
How do I know activemq in the volumn is / data / activemq, how do you know which port it
You can first default docker run --name myactivemq webcenter / activemq after performing a first
execution
docker inspect myactivemq
Can be obtained from the nodes to the Config follows
"Config": {
"Hostname": "3d8ee09e3acb",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"1883/tcp": {},
"5672/tcp": {},
"61613/tcp": {},
"61614/tcp": {},
"61616/tcp": {},
"8161/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"ACTIVEMQ_CONFIG_DIR=/opt/activemq/conf.tmp",
"ACTIVEMQ_DATA_DIR=/data/activemq"
],
"Cmd": [
"/app/run.sh"
],
"ArgsEscaped": true,
"Image": "webcenter/activemq",
"Volumes": {
"/data/activemq": {},
"/opt/activemq/conf": {},
"/var/log/activemq": {}
},
"WorkingDir": "/opt/activemq",
"Entrypoint": null,
"OnBuild": null,
"Labels": {}
}
4. docker encountered problems
- Question 1
docker: Error response from daemon: driver failed programming external connectivity on endpoint jenkins (322630d9843d744f8efa4ce07632025c0105a5933a42e3413ea6d4538b41aeba): (iptables failed: iptables --wait -t nat -A DOCKER -p tcp -d 0/0 --dport 8686 -j DNAT --to-destination 172.17.0.2:8080 ! -i docker0: iptables: No chain/target/match by that nam
solve:
systemctl restart docker