Common container startup commands
# postgre starts the command and sets the connection number
docker run -itd --name postgresql --restart always -e TZ=Asia/Shanghai -v /etc/localtime:/etc/localtime:ro -e POSTGRES_USER=sde \
-ePOSTGRES_PASSWORD = postgres - v/opt/data/postgresql: / var/lib/postgresql/data - p, 5432:5432 postgres: 9.6.1 postgres -c max_connections=500# mongo start command
docker run -itd --restart always -e TZ=Asia/Shanghai -v /etc/localtime:/etc/localtime:ro --name mongo -e MONGO_INITDB_ROOT_USERNAME=mongoadmin \
-eMONGO_INITDB_ROOT_PASSWORD=mongopasswd -p 27017:27017 Mongo :4.1.11-bionic --wiredTigerCacheSizeGB 0.8# docker exec -it mongo sh
# mongo -host localhost --port 27017 --username mongoadmin --password mongopasswd
# docker run -itd --restart always -e TZ=Asia/Shanghai -v /etc/localtime:/etc/localtime:ro --name mongo -v /opt/data/mongo/data:/data/db \
# -e MONGO_INITDB_ROOT_USERNAME=mongoadmin -e MONGO_INITDB_ROOT_PASSWORD=mongopasswd -p 27017:27017 mongo:4.1.11-bionic --wiredTigerCacheSizeGB 0.8
# minio start command
docker run -itd --restart always -e TZ=Asia/Shanghai -v /etc/localtime:/etc/localtime:ro --name minio -p 9000:9000 \
-e MINIO_ACCESS_KEY=minio -e MINIO_SECRET_KEY=minio.minio minio/minio:RELEASE.2019-01-16T21-44-08Z server /export
# redis start command
docker run -itd --restart always -eTZ = v/etc/Asia/Shanghai - localtime: / etc/localtime: ro - the name of redis - p 6379:6379 redis: 4.0.9 - alpine# rebbitMQ start command
docker run -itd --restart always -e TZ=Asia/Shanghai -v /etc/localtime:/etc/localtime:ro --name rabbitmq -p 4369:4369 \
-p 5671:5671 -p 5672:5672 -p 25672:25672 -p 15671:15671 -p 15672:15672 rabbitmq:3.6.10-management-alpine
# gitbook start commandDocker run - itd - name gitbook - restart always - v/opt/soft/gitbook/soa: / gitbook - p, 4000:4000 fellah/gitbook: 3.2 sh## MySQL5.7 Set time zone
docker run -itd --restart always -e TZ=Asia/Shanghai -v /etc/localtime:/etc/localtime:ro -eMYSQL_ROOT_PASSWORD=root -p 3306:3306 \ --name mysql mysql:5.7.16 --character-set-server= UTf8mb4 --collation-server=utf8mb4_unicode_ci --init-connect='SET NAMES utf8mb4; ' \
--default-time-zone=From the '+' --innodb-flush-log-at-trx-commit=0 --log-timestamps=SYSTEM \
--sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
docker run -itd --restart always -e TZ=Asia/Shanghai -v /etc/localtime:/etc/localtime:ro -eMYSQL_ROOT_PASSWORD=root -p 3306:3306 \ --name mysql mysql:5.7.21 --character-set-server= UTf8mb4 --collation-server=utf8mb4_unicode_ci --init-connect='SET NAMES utf8mb4; ' \
--default-time-zone=From the '+' --innodb-flush-log-at-trx-commit=0 --log-timestamps=SYSTEM \
--sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
docker run -itd --restart always -e TZ=Asia/Shanghai -v /etc/localtime:/etc/localtime:ro -eMYSQL_ROOT_PASSWORD=root -p 3306:3306 \ --name mysql mysql:5.7.16 --character-set-server= UTf8mb4 --collation-server=utf8mb4_unicode_ci --init-connect='SET NAMES utf8mb4; ' \
--default-time-zone=From the '+' --log-timestamps=SYSTEM --sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
## MySQL8 Set the time zone
docker run -itd --restart always -e TZ=Asia/Shanghai -v /etc/localtime:/etc/localtime:ro -eMYSQL_ROOT_PASSWORD=root -p 3306:3306 \ --name mysql mysql:8.0.11 --character-set-server= UTf8mb4 --collation-server=utf8mb4_unicode_ci --init-connect='SET NAMES utf8mb4; ' \
--default-time-zone=From the '+' --log-timestamps=SYSTEM --sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' \
--default_authentication_plugin=mysql_native_password
# swagger-editor Start commandDocker run-itd --restart always --name swagger-editor -p 18080:8080 swaggerAPI/swagger-Editor :v3.5.3# Swagger- UI start commandDocker run-itd --restart always --name swagger-ui -p 18081:8080 SwaggerAPI /swagger-ui:3.17.6 Docker run-itd --restart always --name swagger-ui -p 80:8080-eAPI_URL = http://generator.swagger.io/api/swagger.json swaggerapi/swagger - UI: 3.17.6# neo4j container command
docker run -itd --restart always -e TZ=Asia/Shanghai -v /etc/localtime:/etc/localtime:ro --name neo4j -e NEO4j_AUTH=neo4j/admin123 \
-e NEO4J_dbms_tx__log_rotation_retention__policy=true -e NEO4J_dbms_memory_pagecache_size=128M -e NEO4J_dbms_memory_heap_initial__size=128M \
-e NEO4J_dbms_memory_heap_max__size=256M -p 7474:7474 -p 7473:7473 -p 7687:7687 neo4j:3.4.5
docker run -itd --restart always -e TZ=Asia/Shanghai -v /etc/localtime:/etc/localtime:ro -p 5432:5432 -v /cityworks/postgresql:/var/lib/postgresql/data \
--name postgres -e POSTGRES_USER=sde -ePOSTGRES_PASSWORD = postgres postgres: 9.6.1MySQL startup command
docker run -itd --restart always -e TZ=Asia/Shanghai -v /etc/localtime:/etc/localtime:ro --name mysql -eMYSQL_ROOT_PASSWORD = root -p mysql 3306-3306:5.7.3# nginx command
docker run -itd --restart always --name nginx -e TZ=Asia/Shanghai -p 80:80 -v /etc/localtime:/etc/localtime:ro -v /var/log/nginx/:/var/log/nginx \ -v /home/kk/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /usr/share/nginx/html/:/usr/share/nginx/html Nginx: 1.15.4 - alpineCopy the code
Docker Inspect common name command
The following commands cannot check the container IP of a custom nic:
docker inspect --format '{{ .NetworkSettings.IPAddress }}'Docker inspect Container name Docker inspect-f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}'Container name docker inspect container name | grep"IPAddress" -n
Get all container names and their IP addresses with a single command
docker inspect -f '{{.Name}} - {{.NetworkSettings.IPAddress }}' $(docker ps -aq)
Copy the code
Specify the hostname of the container
# --hostname: specify hostname;
# docker run -itd --restart always --name redis --hostname=redis -p 6379:6379 redis:4.0.9-alpineDocker run -itd --restart always --name redis --hostname redis -p 6379:6379 redis:4.0.9-alpineCopy the code
Add hosts to /etc/hosts of the container
# --add-host: specifies the host to add to /etc/hostsDocker run --restart always-itd --name hadoop1 --hostname hadoop1 --net hadoop-network -- IP 10.2.2.1 --add-host Hadoop2:10.2.2.2 - add - host hadoop3:10.2.2.3 hadoop: masterCopy the code
Use Docker to create network segments and assign container IP addresses
Docker network rm docker-swarm-network docker network create --subnet=10.10.10.0/24 docker-swarm-network docker run-itd --name manager1 --net docker-swarm-network -- IP 10.10.10.101 --restart always docker: 18.03.1-CECopy the code
List the names, IP addresses, and ports of all containers
docker inspect --format='{{.Name}} {{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $(docker ps -aq)
docker inspect --format='{{.Name}} {{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}} {{.Config.ExposedPorts}}' $(docker ps -aq)
docker inspect --format='{{.Name}} {{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}} {{.HostConfig.PortBindings}}' $(docker ps -aq)
docker inspect --format='{{.Name}} {{.NetworkSettings.IPAddress}} {{.HostConfig.PortBindings}}' $(docker ps -aq)
# docker inspect -f '{{.Name}} {{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $(docker ps -aq)
# docker inspect -f '{{.Name}} {{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}} {{.Config.ExposedPorts}}' $(docker ps -aq)
# docker inspect -f '{{.Name}} {{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}} {{.HostConfig.PortBindings}}' $(docker ps -aq)
# docker inspect -f='{{.Name}} {{.NetworkSettings.IPAddress}} {{.HostConfig.PortBindings}}' $(docker ps -aq)
Copy the code
Find the partial noun field of the container name
docker ps -a --filter name=redis -q
# 7c16765f5ef3
# ecba9578534c
# c1353a0c7231
# 8a3339228398
docker stop `docker ps -a -q --filter name=redis`
docker rm `docker ps -a -q --filter name=redis`
Copy the code
Export and import docker images
Docker save mysql: 5.7 the node: 8 | gzip > images. The tar. Gz# compress compress multiple images
docker load < images.tar.gz # import image
Copy the code
Docker faQs
- Failed to get D-Bus connection: Operation not permitted
- This error is reported because Dbus-Daemon is not started. It is not that the systemctl command cannot be used in the container
# docker run with --privileged parameter
/usr/sbin/init The Docker container automatically starts services like DBUS.
Copy the code