docker 操作环境ubu16.04
root@53d0a643a2c7:/# quit
bash: quit: command not found
root@53d0a643a2c7:/# exit
exit
-->@coder:~$ sudo docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
-->@coder:~$ sudo docker run e76b /bin/sh -c "while true; do echo hello world; sleep 1; done"
hello world
hello world
hello world
hello world
hello world
^C-->@coder:~$ sudo docker run -d e76b /bin/sh -c "while true; do echo hello world; sleep 1; done"
e816e1fad8b66a483f2f83baccee4d3fc76747ab4ccfb16ae00b181d1934aaf6
-->@coder:~$ sudo docker logs
"docker logs" requires exactly 1 argument.
See 'docker logs --help'.
Usage: docker logs [OPTIONS] CONTAINER
Fetch the logs of a container
-->@coder:~$ sudo docker logs --help
Usage: docker logs [OPTIONS] CONTAINER
Fetch the logs of a container
Options:
--details Show extra details provided to logs
-f, --follow Follow log output
--since string Show logs since timestamp (e.g. 2013-01-02T13:23:37) or relative (e.g. 42m for 42 minutes)
--tail string Number of lines to show from the end of the logs (default "all")
-t, --timestamps Show timestamps
--until string Show logs before a timestamp (e.g. 2013-01-02T13:23:37) or relative (e.g. 42m for 42 minutes)
-->@coder:~$ sudo docker logs -f
"docker logs" requires exactly 1 argument.
See 'docker logs --help'.
Usage: docker logs [OPTIONS] CONTAINER
Fetch the logs of a container
-->@coder:~$ sudo docker logs --details
"docker logs" requires exactly 1 argument.
See 'docker logs --help'.
Usage: docker logs [OPTIONS] CONTAINER
Fetch the logs of a container
-->@coder:~$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e816e1fad8b6 e76b "/bin/sh -c 'while t…" About a minute ago Up About a minute elated_meitner
-->@coder:~$ sudo docker logs e816
hello world
hello world
hello world
hello world
hello world
-->@coder:~$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e816e1fad8b6 e76b "/bin/sh -c 'while t…" About a minute ago Up About a minute elated_meitner
70b5e6a00101 e76b "/bin/sh -c 'while t…" 2 minutes ago Exited (0) 2 minutes ago wizardly_shaw
53d0a643a2c7 e76b "/bin/bash" 6 minutes ago Exited (127) 3 minutes ago jovial_williams
6771348f608f e76b "/bin/echo 'hello wo…" 7 minutes ago Exited (0) 6 minutes ago flamboyant_shtern
5a2a21ea4579 myweb:v1 "nginx -g 'daemon of…" 18 hours ago Exited (255) 25 minutes ago 0.0.0.0:80->80/tcp web
0e83d3c0c655 231d40e811cd "/bin/sh -c 'apt-get…" 18 hours ago Exited (1) 18 hours ago sweet_satoshi
18c8ffceebfb myip "-i" 19 hours ago Created upbeat_satoshi
3a2c6456820f myip "-i" 19 hours ago Created distracted_lumiere
a5acd4cc83ef myip "curl -s http://ip.cn" 19 hours ago Exited (7) 19 hours ago brave_dewdney
a279c8cb0430 nginx:v2 "nginx -g 'daemon of…" 21 hours ago Exited (0) 18 hours ago web2
e188b46041a5 nginx "nginx -g 'daemon of…" 21 hours ago Exited (0) 18 hours ago webserver
-->@coder:~$ sudo docker container stop e816
e816
-->@coder:~$ sudo docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
-->@coder:~$ sudo docker container ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
-->@coder:~$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
-->@coder:~$ sudo docker container status
Usage: docker container COMMAND
Manage containers
Commands:
attach Attach local standard input, output, and error streams to a running container
commit Create a new image from a container's changes
cp Copy files/folders between a container and the local filesystem
create Create a new container
diff Inspect changes to files or directories on a container's filesystem
exec Run a command in a running container
export Export a container's filesystem as a tar archive
inspect Display detailed information on one or more containers
kill Kill one or more running containers
logs Fetch the logs of a container
ls List containers
pause Pause all processes within one or more containers
port List port mappings or a specific mapping for the container
prune Remove all stopped containers
rename Rename a container
restart Restart one or more containers
rm Remove one or more containers
run Run a command in a new container
start Start one or more stopped containers
stats Display a live stream of container(s) resource usage statistics
stop Stop one or more running containers
top Display the running processes of a container
unpause Unpause all processes within one or more containers
update Update configuration of one or more containers
wait Block until one or more containers stop, then print their exit codes
Run 'docker container COMMAND --help' for more information on a command.
-->@coder:~$ sudo docker container stats
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
q
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
-->@coder:~$ sudo docker container
Usage: docker container COMMAND
Manage containers
Commands:
attach Attach local standard input, output, and error streams to a running container
commit Create a new image from a container's changes
cp Copy files/folders between a container and the local filesystem
create Create a new container
diff Inspect changes to files or directories on a container's filesystem
exec Run a command in a running container
export Export a container's filesystem as a tar archive
inspect Display detailed information on one or more containers
kill Kill one or more running containers
logs Fetch the logs of a container
ls List containers
pause Pause all processes within one or more containers
port List port mappings or a specific mapping for the container
prune Remove all stopped containers
rename Rename a container
restart Restart one or more containers
rm Remove one or more containers
run Run a command in a new container
start Start one or more stopped containers
stats Display a live stream of container(s) resource usage statistics
stop Stop one or more running containers
top Display the running processes of a container
unpause Unpause all processes within one or more containers
update Update configuration of one or more containers
wait Block until one or more containers stop, then print their exit codes
Run 'docker container COMMAND --help' for more information on a command.
-->@coder:~$
-->@coder:~$ sudo docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
-->@coder:~$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
-->@coder:~$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e816e1fad8b6 e76b "/bin/sh -c 'while t…" 6 minutes ago Exited (137) 3 minutes ago elated_meitner
70b5e6a00101 e76b "/bin/sh -c 'while t…" 7 minutes ago Exited (0) 6 minutes ago wizardly_shaw
53d0a643a2c7 e76b "/bin/bash" 11 minutes ago Exited (127) 8 minutes ago jovial_williams
6771348f608f e76b "/bin/echo 'hello wo…" 11 minutes ago Exited (0) 11 minutes ago flamboyant_shtern
5a2a21ea4579 myweb:v1 "nginx -g 'daemon of…" 18 hours ago Exited (255) 30 minutes ago 0.0.0.0:80->80/tcp web
0e83d3c0c655 231d40e811cd "/bin/sh -c 'apt-get…" 19 hours ago Exited (1) 19 hours ago sweet_satoshi
18c8ffceebfb myip "-i" 19 hours ago Created upbeat_satoshi
3a2c6456820f myip "-i" 19 hours ago Created distracted_lumiere
a5acd4cc83ef myip "curl -s http://ip.cn" 19 hours ago Exited (7) 19 hours ago brave_dewdney
a279c8cb0430 nginx:v2 "nginx -g 'daemon of…" 21 hours ago Exited (0) 18 hours ago web2
e188b46041a5 nginx "nginx -g 'daemon of…" 21 hours ago Exited (0) 18 hours ago webserver
-->@coder:~$ sudo docker run -idt ubuntu
Unable to find image 'ubuntu:latest' locally
latest: Pulling from library/ubuntu
Digest: sha256:6e9f67fa63b0323e9a1e587fd71c561ba48a034504fb804fd26fd8800039835d
Status: Downloaded newer image for ubuntu:latest
ae3899f543f7025e4d9cadf562c80f364e162346f0241928a5dd865e7d198988
-->@coder:~$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ae3899f543f7 ubuntu "/bin/bash" 17 seconds ago Up 15 seconds mystifying_bardeen
-->@coder:~$ sudo docker attach mystifying_bardeen
root@ae3899f543f7:/# exit
exit
-->@coder:~$ sudo whereis nsenter
nsenter: /usr/bin/nsenter /usr/share/man/man1/nsenter.1.gz
-->@coder:~$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
-->@coder:~$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ae3899f543f7 ubuntu "/bin/bash" 3 minutes ago Exited (0) About a minute ago mystifying_bardeen
e816e1fad8b6 e76b "/bin/sh -c 'while t…" 15 minutes ago Exited (137) 12 minutes ago elated_meitner
70b5e6a00101 e76b "/bin/sh -c 'while t…" 16 minutes ago Exited (0) 15 minutes ago wizardly_shaw
53d0a643a2c7 e76b "/bin/bash" 20 minutes ago Exited (127) 17 minutes ago jovial_williams
6771348f608f e76b "/bin/echo 'hello wo…" 20 minutes ago Exited (0) 20 minutes ago flamboyant_shtern
5a2a21ea4579 myweb:v1 "nginx -g 'daemon of…" 19 hours ago Exited (255) 39 minutes ago 0.0.0.0:80->80/tcp web
0e83d3c0c655 231d40e811cd "/bin/sh -c 'apt-get…" 19 hours ago Exited (1) 19 hours ago sweet_satoshi
18c8ffceebfb myip "-i" 19 hours ago Created upbeat_satoshi
3a2c6456820f myip "-i" 19 hours ago Created distracted_lumiere
a5acd4cc83ef myip "curl -s http://ip.cn" 19 hours ago Exited (7) 19 hours ago brave_dewdney
a279c8cb0430 nginx:v2 "nginx -g 'daemon of…" 21 hours ago Exited (0) 19 hours ago web2
e188b46041a5 nginx "nginx -g 'daemon of…" 22 hours ago Exited (0) 19 hours ago webserver
-->@coder:~$ man nsenter
NSENTER(1) User Commands NSENTER(1)
NAME
nsenter - run program with namespaces of other processes
SYNOPSIS
nsenter [options] [program [arguments]]
DESCRIPTION
Enters the namespaces of one or more other processes and then executes the specified program. Enterable namespaces are:
mount namespace
Mounting and unmounting filesystems will not affect the rest of the system (CLONE_NEWNS flag), except for filesystems which are explicitly marked as shared (with
mount --make-shared; see /proc/self/mountinfo for the shared flag).
UTS namespace
Setting hostname or domainname will not affect the rest of the system. (CLONE_NEWUTS flag)
IPC namespace
The process will have an independent namespace for System V message queues, semaphore sets and shared memory segments. (CLONE_NEWIPC flag)
network namespace
The process will have independent IPv4 and IPv6 stacks, IP routing tables, firewall rules, the /proc/net and /sys/class/net directory trees, sockets, etc.
(CLONE_NEWNET flag)
PID namespace
Children will have a set of PID to process mappings separate from the nsenter process (CLONE_NEWPID flag). nsenter will fork by default if changing the PID
namespace, so that the new program and its children share the same PID namespace and are visible to each other. If --no-fork is used, the new program will be
exec'ed without forking.
user namespace
The process will have a distinct set of UIDs, GIDs and capabilities. (CLONE_NEWUSER flag)
See clone(2) for the exact semantics of the flags.
If program is not given, then ``${SHELL}'' is run (default: /bin/sh).
OPTIONS
-t, --target pid
Specify a target process to get contexts from. The paths to the contexts specified by pid are:
/proc/pid/ns/mnt the mount namespace
/proc/pid/ns/uts the UTS namespace
/proc/pid/ns/ipc the IPC namespace
/proc/pid/ns/net the network namespace
/proc/pid/ns/pid the PID namespace
/proc/pid/ns/user the user namespace
/proc/pid/root the root directory
/proc/pid/cwd the working directory respectively
-m, --mount[=file]
Enter the mount namespace. If no file is specified, enter the mount namespace of the target process. If file is specified, enter the mount namespace specified
by file.
-u, --uts[=file]
Enter the UTS namespace. If no file is specified, enter the UTS namespace of the target process. If file is specified, enter the UTS namespace specified by
file.
-i, --ipc[=file]
Enter the IPC namespace. If no file is specified, enter the IPC namespace of the target process. If file is specified, enter the IPC namespace specified by
file.
-n, --net[=file]
Enter the network namespace. If no file is specified, enter the network namespace of the target process. If file is specified, enter the network namespace spec‐
ified by file.
-p, --pid[=file]
Enter the PID namespace. If no file is specified, enter the PID namespace of the target process. If file is specified, enter the PID namespace specified by
file.
-U, --user[=file]
Enter the user namespace. If no file is specified, enter the user namespace of the target process. If file is specified, enter the user namespace specified by
file. See also the --setuid and --setgid options.
-G, --setgid gid
Set the group ID which will be used in the entered namespace and drop supplementary groups. nsenter(1) always sets GID for user namespaces, the default is 0.
-S, --setuid uid
Set the user ID which will be used in the entered namespace. nsenter(1) always sets UID for user namespaces, the default is 0.
--preserve-credentials
Don't modify UID and GID when enter user namespace. The default is to drops supplementary groups and sets GID and UID to 0.
-r, --root[=directory]
Set the root directory. If no directory is specified, set the root directory to the root directory of the target process. If directory is specified, set the
root directory to the specified directory.
-w, --wd[=directory]
Set the working directory. If no directory is specified, set the working directory to the working directory of the target process. If directory is specified,
set the working directory to the specified directory.
-F, --no-fork
Do not fork before exec'ing the specified program. By default, when entering a PID namespace, nsenter calls fork before calling exec so that any children will
also be in the newly entered PID namespace.
-Z, --follow-context
Set the SELinux security context used for executing a new process according to already running process specified by --target PID. (The util-linux has to be com‐
piled with SELinux support otherwise the option is unavailable.)
-V, --version
Display version information and exit.
-h, --help
Display help text and exit.
SEE ALSO
setns(2), clone(2)
AUTHORS
Eric Biederman ⟨biederm@xmission.com⟩
Karel Zak ⟨kzak@redhat.com⟩
AVAILABILITY
The nsenter command is part of the util-linux package and is available from Linux Kernel Archive ⟨ftp://ftp.kernel.org/pub/linux/utils/util-linux/⟩.
util-linux June 2013 NSENTER(1)
-->@coder:~$ docker inspect --format "{{ .State.Pid }}" myip
unknown shorthand flag: 'm' in -myip
See 'docker inspect --help'.
-->@coder:~$ sudo docker run -idt ubuntu
8cb6ebee1aa1e62cd0cf4c870d210c1033f5e559b950c9121cf597f798bfdf71
-->@coder:~$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8cb6ebee1aa1 ubuntu "/bin/bash" 7 seconds ago Up 5 seconds jolly_cannon
-->@coder:~$ PID=$(sudo docker-pid 8cb6)
sudo: docker-pid:找不到命令
-->@coder:~$ PID=$(sudo docker -pid 8cb6)
unknown shorthand flag: 'p' in -pid
See 'docker --help'.
Usage: docker [OPTIONS] COMMAND
A self-sufficient runtime for containers
Options:
--config string Location of client config files (default "/home/coder/.docker")
-c, --context string Name of the context to use to connect to the daemon (overrides DOCKER_HOST env var and default context set with "docker context use")
-D, --debug Enable debug mode
-H, --host list Daemon socket(s) to connect to
-l, --log-level string Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info")
--tls Use TLS; implied by --tlsverify
--tlscacert string Trust certs signed only by this CA (default "/home/coder/.docker/ca.pem")
--tlscert string Path to TLS certificate file (default "/home/coder/.docker/cert.pem")
--tlskey string Path to TLS key file (default "/home/coder/.docker/key.pem")
--tlsverify Use TLS and verify the remote
-v, --version Print version information and quit
Management Commands:
builder Manage builds
config Manage Docker configs
container Manage containers
context Manage contexts
engine Manage the docker engine
image Manage images
network Manage networks
node Manage Swarm nodes
plugin Manage plugins
secret Manage Docker secrets
service Manage services
stack Manage Docker stacks
swarm Manage Swarm
system Manage Docker
trust Manage trust on Docker images
volume Manage volumes
Commands:
attach Attach local standard input, output, and error streams to a running container
build Build an image from a Dockerfile
commit Create a new image from a container's changes
cp Copy files/folders between a container and the local filesystem
create Create a new container
diff Inspect changes to files or directories on a container's filesystem
events Get real time events from the server
exec Run a command in a running container
export Export a container's filesystem as a tar archive
history Show the history of an image
images List images
import Import the contents from a tarball to create a filesystem image
info Display system-wide information
inspect Return low-level information on Docker objects
kill Kill one or more running containers
load Load an image from a tar archive or STDIN
login Log in to a Docker registry
logout Log out from a Docker registry
logs Fetch the logs of a container
pause Pause all processes within one or more containers
port List port mappings or a specific mapping for the container
ps List containers
pull Pull an image or a repository from a registry
push Push an image or a repository to a registry
rename Rename a container
restart Restart one or more containers
rm Remove one or more containers
rmi Remove one or more images
run Run a command in a new container
save Save one or more images to a tar archive (streamed to STDOUT by default)
search Search the Docker Hub for images
start Start one or more stopped containers
stats Display a live stream of container(s) resource usage statistics
stop Stop one or more running containers
tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
top Display the running processes of a container
unpause Unpause all processes within one or more containers
update Update configuration of one or more containers
version Show the Docker version information
wait Block until one or more containers stop, then print their exit codes
Run 'docker COMMAND --help' for more information on a command.
-->@coder:~$ sudo docker --help
Usage: docker [OPTIONS] COMMAND
A self-sufficient runtime for containers
Options:
--config string Location of client config files (default "/home/coder/.docker")
-c, --context string Name of the context to use to connect to the daemon (overrides DOCKER_HOST env var and default context set with "docker context use")
-D, --debug Enable debug mode
-H, --host list Daemon socket(s) to connect to
-l, --log-level string Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info")
--tls Use TLS; implied by --tlsverify
--tlscacert string Trust certs signed only by this CA (default "/home/coder/.docker/ca.pem")
--tlscert string Path to TLS certificate file (default "/home/coder/.docker/cert.pem")
--tlskey string Path to TLS key file (default "/home/coder/.docker/key.pem")
--tlsverify Use TLS and verify the remote
-v, --version Print version information and quit
Management Commands:
builder Manage builds
config Manage Docker configs
container Manage containers
context Manage contexts
engine Manage the docker engine
image Manage images
network Manage networks
node Manage Swarm nodes
plugin Manage plugins
secret Manage Docker secrets
service Manage services
stack Manage Docker stacks
swarm Manage Swarm
system Manage Docker
trust Manage trust on Docker images
volume Manage volumes
Commands:
attach Attach local standard input, output, and error streams to a running container
build Build an image from a Dockerfile
commit Create a new image from a container's changes
cp Copy files/folders between a container and the local filesystem
create Create a new container
diff Inspect changes to files or directories on a container's filesystem
events Get real time events from the server
exec Run a command in a running container
export Export a container's filesystem as a tar archive
history Show the history of an image
images List images
import Import the contents from a tarball to create a filesystem image
info Display system-wide information
inspect Return low-level information on Docker objects
kill Kill one or more running containers
load Load an image from a tar archive or STDIN
login Log in to a Docker registry
logout Log out from a Docker registry
logs Fetch the logs of a container
pause Pause all processes within one or more containers
port List port mappings or a specific mapping for the container
ps List containers
pull Pull an image or a repository from a registry
push Push an image or a repository to a registry
rename Rename a container
restart Restart one or more containers
rm Remove one or more containers
rmi Remove one or more images
run Run a command in a new container
save Save one or more images to a tar archive (streamed to STDOUT by default)
search Search the Docker Hub for images
start Start one or more stopped containers
stats Display a live stream of container(s) resource usage statistics
stop Stop one or more running containers
tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
top Display the running processes of a container
unpause Unpause all processes within one or more containers
update Update configuration of one or more containers
version Show the Docker version information
wait Block until one or more containers stop, then print their exit codes
Run 'docker COMMAND --help' for more information on a command.
-->@coder:~$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8cb6ebee1aa1 ubuntu "/bin/bash" 5 minutes ago Up 5 minutes jolly_cannon
-->@coder:~$ PID=$(sudo docker inspect --format "{{ .State.Pid}}" 8cb6)
-->@coder:~$ PID=$(sudo docker inspect --format "{{ .State.Pid}}" jolly_cannon)
-->@coder:~$ echo PID
PID
-->@coder:~$ echo $PID
6333
-->@coder:~$ XID=$(sudo docker inspect --format "{{ .State.Pid}}" 8cb6)
-->@coder:~$ echo ${XID}
6333
-->@coder:~$ man docker-pid
没有 docker-pid 的手册页条目
-->@coder:~$ sudo apt-get docker-pid
E: 无效的操作 docker-pid
-->@coder:~$ sudo apt-cache search docker-pid
-->@coder:~$ sudo nsenter --target $PID --mount --uts --ipc --net --pid
root@8cb6ebee1aa1:/# pwd
/
root@8cb6ebee1aa1:/# ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
root@8cb6ebee1aa1:/# echo $SHELL
/bin/bash
root@8cb6ebee1aa1:/# exit
logout
-->@coder:~$ wget -P ~ https://github.com/yeasy/docker_practice/raw/master/
--2019-12-05 11:25:49-- https://github.com/yeasy/docker_practice/raw/master/
正在解析主机 github.com (github.com)... 52.74.223.119
正在连接 github.com (github.com)|52.74.223.119|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 404 Not Found
2019-12-05 11:25:51 错误 404:Not Found。
-->@coder:~$ _local/.bashrc_docker;
-su: _local/.bashrc_docker: 没有那个文件或目录
-->@coder:~$ man wget
WGET(1) GNU Wget WGET(1)
NAME
Wget - The non-interactive network downloader.
SYNOPSIS
wget [option]... [URL]...
WGET(1) GNU Wget WGET(1)
NAME
Wget - The non-interactive network downloader.
SYNOPSIS
wget [option]... [URL]...
WGET(1) GNU Wget WGET(1)
NAME
Wget - The non-interactive network downloader.
SYNOPSIS
wget [option]... [URL]...
...skipping...
If you just want to get rid of the directory structure, this option is similar to a combination of -nd and -P. However, unlike -nd, --cut-dirs does not lose with
subdirectories---for instance, with -nH --cut-dirs=1, a beta/ subdirectory will be placed to xemacs/beta, as one would expect.
-P prefix
--directory-prefix=prefix
Set directory prefix to prefix. The directory prefix is the directory where all other files and subdirectories will be saved to, i.e. the top of the retrieval tree.
The default is . (the current directory).
[END] 2019/12/5 11:29:32