1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# Search image
docker search [imange name]
# Start/Stop Container
docker start/stop [containerID]
# Running container status
docker ps
# Enter the container
docker attach [containerID]
# Enter container by root user
docker exec -it -u root <container id> bash
# Create a container and run it
docker run -it ubuntu:14.04 /bin/bash
# Slove the problem than process 1 is not "init"
docker run -tid --name centos8 --privileged=true -p 3306:3306centos:latest /sbin/init
docker exec -it test /bin/bash
# Create a container with mysql
docker run -itd --name mysql-test -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql
sudo docker exec -it mysql bash
# Create a container with sqlserver
docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=yourStrong(!)Password" -p 1433:1433 --name sqlserver2019 -d mcr.microsoft.com/mssql/server:latest
sudo docker exec -it sqlserver2019 "bash"
# Create a container via special collation
# eg:
# > docker run \
# --name=mssql \
# --hostname=my-docker-mssql \
# -d \
# -e 'ACCEPT_EULA=Y' \
# -e 'SA_PASSWORD=mssqllinux@1' \
# -e 'MSSQL_LCID=1041' \
# -e 'MSSQL_COLLATION=Japanese_CI_AS' \
# -p 1433:1433 \
# microsoft/mssql-server-linux:latest
docker run --name=mssql -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=yourStrong(!)Password" -e 'MSSQL_COLLATION=Japanese_90_CI_AS' -p 1433:1433 -d mcr.microsoft.com/mssql/server:latest
# Copy data to container
# Format: docker cp {from path} {container name}:{to path}
# eg:
docker cp C:\Users\xx\xx\xx.bak sqlerver2019:/var/opt/mssql/data
# Create a container with postgresql
docker run --name mypostgres -e POSTGRES_PASSWORD=password -d -p 5432:5432 postgres
# Create a container with redis image
docker pull redis:latest
docker run -itd --name myred -p 6379:6379 redis --requirepass 123456
docker exec -it myred /bin/bash
#run redis command line
redis-cli
#为现有redis设置密码:
redis-cli
config get reuirepass #查看现有密码
config set requirepass xxxxxx #设置密码
#login
auth "123456"
# Create a container with rabbitMQ
docker pull rabbitmq:management #带管理界面
docker run -dit --name myrabbitmq -e RABBITMQ_DEFAULT_USER=admin -e RABBITMQ_DEFAULT_PASS=admin -p 15672:15672 -p 5672:5672 rabbitmq:management
# rename
docker rename 旧名 新名
# Delete image
docker rmi [image]
# Delete container
docker rm [container ID|NAME]
# Delete all stoped containers
docker rm $(docker ps -a -q)
# Run a container with port mapping
docker run -it -d -p 8083:80 centos:latest /bin/bash
# Check the port config
docker port [containerID]
# Start/Stop all containers
docker start/stop $(docker ps -a | awk '{ print $1}' | tail -n +2)
# Delete all containers
docker rm $(docker ps -a | awk '{ print $1}' | tail -n +2)
# Delete all images
docker rmi $(docker images | awk '{print $3}' |tail -n +2)
|