[root@localhost etc]# docker run -it ubuntu /bin/bash
root@d9c81eb09ef1:/#
指定名称启动–name
[root@localhost etc]# docker run -it --name=u1 ubuntu /bin/bash
查看启动的docker容器实例
[root@localhost etc]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d9c81eb09ef1 ubuntu "/bin/bash" 9 hours ago Up 9 hours focused_proskuriakova
[root@localhost etc]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3499e2cf3d1c ubuntu "/bin/bash" 19 seconds ago Up 18 seconds u1
d9c81eb09ef1 ubuntu "/bin/bash" 10 hours ago Up 10 hours focused_proskuriakova
查看历史记录
[root@localhost etc]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3499e2cf3d1c ubuntu "/bin/bash" 9 minutes ago Up 9 minutes u1
d9c81eb09ef1 ubuntu "/bin/bash" 10 hours ago Up 10 hours focused_proskuriakova
ac67d6ae8d61 ubuntu "/bin/bash" 10 hours ago Exited (0) 10 hours ago serene_johnson
1f7b023b8a12 ubuntu "bash" 10 hours ago Exited (127) 10 hours ago amazing_carver
d4cad94c2b5b feb5d9fea6a5 "/hello" 26 hours ago Exited (0) 26 hours ago infallible_payne
906747c232cb feb5d9fea6a5 "/hello" 27 hours ago Exited (0) 27 hours ago relaxed_mendel
327aa17a0154 feb5d9fea6a5 "/hello" 27 hours ago Exited (0) 27 hours ago cranky_diffie
59870e025231 feb5d9fea6a5 "/hello" 5 days ago Exited (0) 5 days ago hungry_mestorf
e07f9af080a4 feb5d9fea6a5 "/hello" 5 days ago Exited (0) 5 days ago epic_elgamal
查看最近启动实例
[root@localhost etc]# docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3499e2cf3d1c ubuntu "/bin/bash" 11 minutes ago Up 11 minutes u1
查看最近n条记录
[root@localhost etc]# docker ps -n 1
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3499e2cf3d1c ubuntu "/bin/bash" 17 minutes ago Up 17 minutes u1
二、后台守护式启动
[root@localhost ~]# docker run -d --name=r1 redis
dc55ae800635501bae6011916e335d34faa725a074a0e05daa60791f81f419ab
[root@localhost ~]#
查看启动是否成功
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
dc55ae800635 redis "docker-entrypoint.s…" 5 seconds ago Up 4 seconds 6379/tcp r1
dd1b2c4e684f ubuntu "bash" 18 hours ago Up 7 minutes u1
9ea72b383053 ubuntu "bash" 18 hours ago Up 7 minutes u2
查看进程日志
[root@localhost ~]# docker logs dc55ae800635
1:C 07 Aug 2022 09:44:29.412 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1:C 07 Aug 2022 09:44:29.413 # Redis version=6.2.6, bits=64, commit=00000000, modified=0, pid=1, just started
1:C 07 Aug 2022 09:44:29.413 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
1:M 07 Aug 2022 09:44:29.414 * monotonic clock: POSIX clock_gettime
1:M 07 Aug 2022 09:44:29.415 * Running mode=standalone, port=6379.
1:M 07 Aug 2022 09:44:29.415 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
1:M 07 Aug 2022 09:44:29.415 # Server initialized
1:M 07 Aug 2022 09:44:29.415 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
1:M 07 Aug 2022 09:44:29.416 * Ready to accept connections
查看容器内进程
此时仅运行了root
[root@localhost ~]# docker top dd1b2c4e684f
UID PID PPID C STIME TTY TIME CMD
root 72739 72718 0 18:12 pts/0 00:00:00 bash