[root@localhost ~]# docker pull centos Using default tag: latest latest: Pulling from library/centos
[root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest feb5d9fea6a5 4 months ago 13.3kB
[root@localhost ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 0ab3a4609ecc hello-world "/hello" 4 minutes ago Exited (0) 4 minutes ago sleepy_turing
[root@localhost ~]# docker rm 0ab3a4609ecc 0ab3a4609ecc
[root@localhost ~]# docker rmi -f $(docker images -qa) Untagged: hello-world:latest Untagged: hello-world@sha256:97a379f4f88575512824f3b352bc03cd75e239179eea0fecc38e597b2209f49a Deleted: sha256:feb5d9fea6a5e9606aa995e879d862b825965ba48de054caab5ef356dc6b3412
[root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE centos latest 5d0da3dc9764 5 months ago 231MB [root@localhost ~]# docker run -it 5d0da3dc9764 [root@3dd0a3a9cca4 /]#
[root@localhost ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 3dd0a3a9cca4 5d0da3dc9764 "/bin/bash" 2 minutes ago Exited (0) 2 minutes ago loving_beaver 2a40735a772a feb5d9fea6a5 "/hello" 7 minutes ago Exited (0) 7 minutes ago exciting_buck [root@localhost ~]# docker start 3dd0a3a9cca4 3dd0a3a9cca4
[root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 3dd0a3a9cca4 5d0da3dc9764 "/bin/bash" 4 minutes ago Up About a minute loving_beaver [root@localhost ~]# docker stop 3dd0a3a9cca4 3dd0a3a9cca4
[root@localhost ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 3dd0a3a9cca4 5d0da3dc9764 "/bin/bash" 5 minutes ago Exited (0) 4 seconds ago loving_beaver [root@localhost ~]# docker rm 3dd0a3a9cca4 3dd0a3a9cca4
[root@localhost ~]# docker ps -qa|xargs docker rm 2a40735a772a
root@localhost ~]# docker run -d centos /bin/sh -c "while true;do echo hello ztf;sleep 2;done" 60a42445f78cbea48f1d23971575084986aee9853255ec9766c9de31094e2f69 [root@localhost ~]# docker logs 60a42445 hello ztf hello ztf
[root@localhost ~]# docker top 60a42445 UID PID PPID C STIME TTY TIME CMD root 3115 3097 0 23:52 ? 00:00:00 /bin/sh -c while true;do echo hello ztf;sleep 2;done root 3186 3115 0 23:53 ? 00:00:00 /usr/bin/coreutils --coreutils-prog-shebang=sleep /usr/bin/sleep 2
[root@localhost ~]# docker inspect 60a42445 [ { "Id": "60a42445f78cbea48f1d23971575084986aee9853255ec9766c9de31094e2f69", "Created": "2022-02-19T15:52:08.782734158Z",
进入正在运行的容器
[root@localhost ~]# docker exec -it 60a42445f78c ls -l /tmp total 12 -rwx------. 1 root root 701 Sep 15 14:17 ks-script-4luisyla -rwx------. 1 root root 671 Sep 15 14:17 ks-script-o23i7rc2
[root@localhost ~]# docker attach 60a42445f78c hello ztf hello ztf
copy容器内的内容
[root@localhost ~]# docker cp 60a42445f78c:/tmp/ks-script-4luisyla .
[root@localhost ~]# docker run -d -p 8080:8080 tomcat 8477d8fd9c51233285a2a77831e7a3bb41d87e790180632825e7a5ec34c5320a
使用mysql
[root@localhost mysql]# docker run -d -p 3306:3306 --name mysql -v /ztf/mysql/conf:/etc/mysql/conf.d -v /ztf/mysql/logs:/logs -v /ztf/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 mysql
[root@localhost ~]# docker exec -it fc35ef1a9d8a bash root@fc35ef1a9d8a:/# mysql -uroot -p123456
systemctl stop firewalld
mysql> use mysql; mysql> grant all privileges on *.* to root@'%' identified by "password";