■この本の内容をやってみた
■
y-ononoMacBook-Pro:117 y_ono$ docker container run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
y-ononoMacBook-Pro:117 y_ono$
y-ononoMacBook-Pro:~ y_ono$ docker container run --name mynginx -d -p 8081:80 nginx
077806e698c1b539399c766b8d5a7d3dc7193ca48ba0c998869403f9cdaf65ee
y-ononoMacBook-Pro:~ y_ono$
y-ononoMacBook-Pro:~ y_ono$ docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
077806e698c1 nginx "/docker-entrypoint.…" 33 seconds ago Up 31 seconds 0.0.0.0:8081->80/tcp mynginx
0fdc6121daf9 nginx "/docker-entrypoint.…" 25 minutes ago Up 25 minutes 0.0.0.0:8080->80/tcp hogehoge
y-ononoMacBook-Pro:~ y_ono$
y-ononoMacBook-Pro:~ y_ono$ docker container stop hogehoge
hogehoge
y-ononoMacBook-Pro:~ y_ono$ docker container stop mynginx
mynginx
y-ononoMacBook-Pro:~ y_ono$
y-ononoMacBook-Pro:~ y_ono$ docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username:
y-ononoMacBook-Pro:~ y_ono$ docker container run nginx
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
<ctrl+c>
y-ononoMacBook-Pro:~ y_ono$ docker container run -it nginx bash
root@53bd8a8744ca:/#
bash操作とキーボード操作のこと
root@53bd8a8744ca:/# exit
exit
y-ononoMacBook-Pro:~ y_ono$ docker container run -name hello1 -d hello-world
unknown shorthand flag: 'n' in -name
See 'docker container run --help'.
y-ononoMacBook-Pro:~ y_ono$ docker container run --name hello1 -d hello-world
593e6006f126d16769f4680069fa486ed2e09d5ec5c326c5afb256e5e6c918db
y-ononoMacBook-Pro:~ y_ono$
y-ononoMacBook-Pro:~ y_ono$ docker container exec mynginx date
Sat Nov 7 11:50:39 UTC 2020
y-ononoMacBook-Pro:~ y_ono$
y-ononoMacBook-Pro:~ y_ono$ docker container exec -it mynginx bash
root@b6117d59c282:/#
コマンドをhostではなくcontainerで使いたい場合のリダイレクト処理について
y-ononoMacBook-Pro:117 y_ono$ docker container exec -it mynginx sh -c "echo 'hello docker' > /hello.txt"
y-ononoMacBook-Pro:117 y_ono$ docker container exec mynginx cat /hello.txt
hello docker
y-ononoMacBook-Pro:117 y_ono$
複雑な処理の場合は、コンテナにシェルスクリプトを書いておき、それを呼び出す方がシンプルです。
y-ononoMacBook-Pro:117 y_ono$ docker help
Usage: docker [OPTIONS] COMMAND
A self-sufficient runtime for containers
Options:
--config string Location of client config files (default "/Users/y_ono/.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 "/Users/y_ono/.docker/ca.pem")
--tlscert string Path to TLS certificate file (default "/Users/y_ono/.docker/cert.pem")
--tlskey string Path to TLS key file (default "/Users/y_ono/.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
image Manage images
network Manage networks
node Manage Swarm nodes
plugin Manage plugins
scan* Docker Scan (Docker Inc., v0.3.4)
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.
y-ononoMacBook-Pro:117 y_ono$
y-ononoMacBook-Pro:117 y_ono$ docker container help
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.
y-ononoMacBook-Pro:117 y_ono$
y-ononoMacBook-Pro:117 y_ono$ docker container run --help
Usage: docker container run [OPTIONS] IMAGE [COMMAND] [ARG...]
Run a command in a new container
Options:
--add-host list Add a custom host-to-IP mapping (host:ip)
-a, --attach list Attach to STDIN, STDOUT or STDERR
--blkio-weight uint16 Block IO (relative weight), between 10 and 1000, or 0 to disable (default 0)
--blkio-weight-device list Block IO weight (relative device weight) (default [])
--cap-add list Add Linux capabilities
--cap-drop list Drop Linux capabilities
--cgroup-parent string Optional parent cgroup for the container
--cidfile string Write the container ID to the file
--cpu-period int Limit CPU CFS (Completely Fair Scheduler) period
--cpu-quota int Limit CPU CFS (Completely Fair Scheduler) quota
--cpu-rt-period int Limit CPU real-time period in microseconds
--cpu-rt-runtime int Limit CPU real-time runtime in microseconds
-c, --cpu-shares int CPU shares (relative weight)
--cpus decimal Number of CPUs
--cpuset-cpus string CPUs in which to allow execution (0-3, 0,1)
--cpuset-mems string MEMs in which to allow execution (0-3, 0,1)
-d, --detach Run container in background and print container ID
--detach-keys string Override the key sequence for detaching a container
--device list Add a host device to the container
--device-cgroup-rule list Add a rule to the cgroup allowed devices list
--device-read-bps list Limit read rate (bytes per second) from a device (default [])
--device-read-iops list Limit read rate (IO per second) from a device (default [])
--device-write-bps list Limit write rate (bytes per second) to a device (default [])
--device-write-iops list Limit write rate (IO per second) to a device (default [])
--disable-content-trust Skip image verification (default true)
--dns list Set custom DNS servers
--dns-option list Set DNS options
--dns-search list Set custom DNS search domains
--domainname string Container NIS domain name
--entrypoint string Overwrite the default ENTRYPOINT of the image
-e, --env list Set environment variables
--env-file list Read in a file of environment variables
--expose list Expose a port or a range of ports
--gpus gpu-request GPU devices to add to the container ('all' to pass all GPUs)
--group-add list Add additional groups to join
--health-cmd string Command to run to check health
--health-interval duration Time between running the check (ms|s|m|h) (default 0s)
--health-retries int Consecutive failures needed to report unhealthy
--health-start-period duration Start period for the container to initialize before starting health-retries countdown
(ms|s|m|h) (default 0s)
--health-timeout duration Maximum time to allow one check to run (ms|s|m|h) (default 0s)
--help Print usage
-h, --hostname string Container host name
--init Run an init inside the container that forwards signals and reaps processes
-i, --interactive Keep STDIN open even if not attached
--ip string IPv4 address (e.g., 172.30.100.104)
--ip6 string IPv6 address (e.g., 2001:db8::33)
--ipc string IPC mode to use
--isolation string Container isolation technology
--kernel-memory bytes Kernel memory limit
-l, --label list Set meta data on a container
--label-file list Read in a line delimited file of labels
--link list Add link to another container
--link-local-ip list Container IPv4/IPv6 link-local addresses
--log-driver string Logging driver for the container
--log-opt list Log driver options
--mac-address string Container MAC address (e.g., 92:d0:c6:0a:29:33)
-m, --memory bytes Memory limit
--memory-reservation bytes Memory soft limit
--memory-swap bytes Swap limit equal to memory plus swap: '-1' to enable unlimited swap
--memory-swappiness int Tune container memory swappiness (0 to 100) (default -1)
--mount mount Attach a filesystem mount to the container
--name string Assign a name to the container
--network network Connect a container to a network
--network-alias list Add network-scoped alias for the container
--no-healthcheck Disable any container-specified HEALTHCHECK
--oom-kill-disable Disable OOM Killer
--oom-score-adj int Tune host's OOM preferences (-1000 to 1000)
--pid string PID namespace to use
--pids-limit int Tune container pids limit (set -1 for unlimited)
--platform string Set platform if server is multi-platform capable
--privileged Give extended privileges to this container
-p, --publish list Publish a container's port(s) to the host
-P, --publish-all Publish all exposed ports to random ports
--read-only Mount the container's root filesystem as read only
--restart string Restart policy to apply when a container exits (default "no")
--rm Automatically remove the container when it exits
--runtime string Runtime to use for this container
--security-opt list Security Options
--shm-size bytes Size of /dev/shm
--sig-proxy Proxy received signals to the process (default true)
--stop-signal string Signal to stop a container (default "SIGTERM")
--stop-timeout int Timeout (in seconds) to stop a container
--storage-opt list Storage driver options for the container
--sysctl map Sysctl options (default map[])
--tmpfs list Mount a tmpfs directory
-t, --tty Allocate a pseudo-TTY
--ulimit ulimit Ulimit options (default [])
-u, --user string Username or UID (format: <name|uid>[:<group|gid>])
--userns string User namespace to use
--uts string UTS namespace to use
-v, --volume list Bind mount a volume
--volume-driver string Optional volume driver for the container
--volumes-from list Mount volumes from the specified container(s)
-w, --workdir string Working directory inside the container
y-ononoMacBook-Pro:117 y_ono$
y-ononoMacBook-Pro:117 y_ono$ docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b6117d59c282 nginx "/docker-entrypoint.…" 15 minutes ago Up 15 minutes 0.0.0.0:8081->80/tcp mynginx
y-ononoMacBook-Pro:117 y_ono$
ls -a で停止しているコンテナも見えるようにする
y-ononoMacBook-Pro:117 y_ono$ docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b6117d59c282 nginx "/docker-entrypoint.…" 15 minutes ago Up 15 minutes 0.0.0.0:8081->80/tcp mynginx
593e6006f126 hello-world "/hello" 5 hours ago Exited (0) 5 hours ago hello1
d7752e14fdb1 nginx:1.14.0 "nginx -g 'daemon of…" 2 days ago Exited (0) 7 hours ago uims-portal-web
a48be28a7f4f uims-api_api "bin/rails s" 2 days ago Exited (1) 7 hours ago uims-portal-api
08ff98534f9f uims-portal_app "npm run dev" 2 days ago Exited (0) 7 hours ago uims-portal-app
32ac52a3cddd mariadb:10.3.8 "docker-entrypoint.s…" 2 days ago Exited (0) 7 hours ago uims-portal-db
3a61a3dd2ef8 uims-api_api "bin/rails s -p 3001…" 2 months ago Exited (1) 2 days ago uims-api
fff025712b77 mariadb:10.3.8 "docker-entrypoint.s…" 2 months ago Exited (0) 7 hours ago uims-api-db
y-ononoMacBook-Pro:117 y_ono$
特定コンテナの情報をみる
y-ononoMacBook-Pro:117 y_ono$ docker container inspect mynginx
[
{
"Id": "b6117d59c282b59473ac3969fe070eee523d78f6baf7394c5315902a12487914",
"Created": "2020-11-07T11:50:05.227771Z",
"Path": "/docker-entrypoint.sh",
"Args": [
"nginx",
"-g",
"daemon off;"
],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 3270,
"ExitCode": 0,
"Error": "",
"StartedAt": "2020-11-07T11:50:05.6721718Z",
"FinishedAt": "0001-01-01T00:00:00Z"
},
"Image": "sha256:c39a868aad02a383c7e490e0fc4a5b0217f667f2de764bc2755e315a5adf64a1",
"ResolvConfPath": "/var/lib/docker/containers/b6117d59c282b59473ac3969fe070eee523d78f6baf7394c5315902a12487914/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/b6117d59c282b59473ac3969fe070eee523d78f6baf7394c5315902a12487914/hostname",
"HostsPath": "/var/lib/docker/containers/b6117d59c282b59473ac3969fe070eee523d78f6baf7394c5315902a12487914/hosts",
"LogPath": "/var/lib/docker/containers/b6117d59c282b59473ac3969fe070eee523d78f6baf7394c5315902a12487914/b6117d59c282b59473ac3969fe070eee523d78f6baf7394c5315902a12487914-json.log",
"Name": "/mynginx",
"RestartCount": 0,
"Driver": "overlay2",
"Platform": "linux",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "",
"ExecIDs": null,
"HostConfig": {
"Binds": null,
"ContainerIDFile": "",
"LogConfig": {
"Type": "json-file",
"Config": {}
},
"NetworkMode": "default",
"PortBindings": {
"80/tcp": [
{
"HostIp": "",
"HostPort": "8081"
}
]
},
"RestartPolicy": {
"Name": "no",
"MaximumRetryCount": 0
},
"AutoRemove": false,
"VolumeDriver": "",
"VolumesFrom": null,
"CapAdd": null,
"CapDrop": null,
"Capabilities": null,
"Dns": [],
"DnsOptions": [],
"DnsSearch": [],
"ExtraHosts": null,
"GroupAdd": null,
"IpcMode": "private",
"Cgroup": "",
"Links": null,
"OomScoreAdj": 0,
"PidMode": "",
"Privileged": false,
"PublishAllPorts": false,
"ReadonlyRootfs": false,
"SecurityOpt": null,
"UTSMode": "",
"UsernsMode": "",
"ShmSize": 67108864,
"Runtime": "runc",
"ConsoleSize": [
0,
0
],
"Isolation": "",
"CpuShares": 0,
"Memory": 0,
"NanoCpus": 0,
"CgroupParent": "",
"BlkioWeight": 0,
"BlkioWeightDevice": [],
"BlkioDeviceReadBps": null,
"BlkioDeviceWriteBps": null,
"BlkioDeviceReadIOps": null,
"BlkioDeviceWriteIOps": null,
"CpuPeriod": 0,
"CpuQuota": 0,
"CpuRealtimePeriod": 0,
"CpuRealtimeRuntime": 0,
"CpusetCpus": "",
"CpusetMems": "",
"Devices": [],
"DeviceCgroupRules": null,
"DeviceRequests": null,
"KernelMemory": 0,
"KernelMemoryTCP": 0,
"MemoryReservation": 0,
"MemorySwap": 0,
"MemorySwappiness": null,
"OomKillDisable": false,
"PidsLimit": null,
"Ulimits": null,
"CpuCount": 0,
"CpuPercent": 0,
"IOMaximumIOps": 0,
"IOMaximumBandwidth": 0,
"MaskedPaths": [
"/proc/asound",
"/proc/acpi",
"/proc/kcore",
"/proc/keys",
"/proc/latency_stats",
"/proc/timer_list",
"/proc/timer_stats",
"/proc/sched_debug",
"/proc/scsi",
"/sys/firmware"
],
"ReadonlyPaths": [
"/proc/bus",
"/proc/fs",
"/proc/irq",
"/proc/sys",
"/proc/sysrq-trigger"
]
},
"GraphDriver": {
"Data": {
"LowerDir": "/var/lib/docker/overlay2/de6acf882865e54dd26d56cc0288996971d22e239d9d7e169a84dde7469fb9bd-init/diff:/var/lib/docker/overlay2/2b2cca916e7a6df810885455c7ba499d3162b1d1b93057ef49a3c43c70fa02bf/diff:/var/lib/docker/overlay2/8f9a2debcd1c6395d5f8fa8cb4975715dcb31ba85ad237998bab7cb622c83b99/diff:/var/lib/docker/overlay2/086ce3e001c730db024d8f3b8e23e53dbc6fac25fe1cd1a62683129ce7997b8a/diff:/var/lib/docker/overlay2/45a7e82547e311229f5161c413a86a23422f4e80b2e5a5c707841ee388383b66/diff:/var/lib/docker/overlay2/a92c2a8ad0f33d9b4d344d8479a23e9f848cedbc16e33d25bea0bb1276981065/diff",
"MergedDir": "/var/lib/docker/overlay2/de6acf882865e54dd26d56cc0288996971d22e239d9d7e169a84dde7469fb9bd/merged",
"UpperDir": "/var/lib/docker/overlay2/de6acf882865e54dd26d56cc0288996971d22e239d9d7e169a84dde7469fb9bd/diff",
"WorkDir": "/var/lib/docker/overlay2/de6acf882865e54dd26d56cc0288996971d22e239d9d7e169a84dde7469fb9bd/work"
},
"Name": "overlay2"
},
"Mounts": [],
"Config": {
"Hostname": "b6117d59c282",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"80/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"NGINX_VERSION=1.19.4",
"NJS_VERSION=0.4.4",
"PKG_RELEASE=1~buster"
],
"Cmd": [
"nginx",
"-g",
"daemon off;"
],
"Image": "nginx",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": [
"/docker-entrypoint.sh"
],
"OnBuild": null,
"Labels": {
"maintainer": "NGINX Docker Maintainers \u003cdocker-maint@nginx.com\u003e"
},
"StopSignal": "SIGTERM"
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "41340469c543e22283aa86fdbf0c4f8a71a371c8e424c969e778524f9f4a4f8e",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"80/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "8081"
}
]
},
"SandboxKey": "/var/run/docker/netns/41340469c543",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "c4d340df9820b6144d37ad42ad62edbcb12fc0e06ef09df3627dd7210ac32480",
"Gateway": "172.17.0.1",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"MacAddress": "02:42:ac:11:00:02",
"Networks": {
"bridge": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "1964f6520d12b84560ce9e0e773389bf4ed979637311a5918b2d3dade8901e34",
"EndpointID": "c4d340df9820b6144d37ad42ad62edbcb12fc0e06ef09df3627dd7210ac32480",
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:11:00:02",
"DriverOpts": null
}
}
}
}
]
y-ononoMacBook-Pro:117 y_ono$
コンテナのログの確認
y-ononoMacBook-Pro:117 y_ono$ docker container run -d -p 8090:80 nginx
4bcc414f095fe0cfa7da0f6ab2b1092e4aacb04e21e43ad36ff1a78b7f3b1e07
y-ononoMacBook-Pro:117 y_ono$ docker container logs 4bcc414f095fe0cfa7da0f6ab2b1092e4aacb04e21e43ad36ff1a78b7f3b1e07
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
y-ononoMacBook-Pro:117 y_ono$
継続してログの表示 -f
y-ononoMacBook-Pro:117 y_ono$ docker container logs -f 4bcc414f095fe0cfa7da0f6ab2b1092e4aacb04e21e43ad36ff1a78b7f3b1e07
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
統計情報--no-stream
y-ononoMacBook-Pro:117 y_ono$ docker container stats --no-stream
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
4bcc414f095f zen_jepsen 0.00% 2.043MiB / 1.941GiB 0.10% 1.08kB / 0B 0B / 8.19kB 2
b6117d59c282 mynginx 0.00% 2.141MiB / 1.941GiB 0.11% 1.37kB / 0B 156kB / 8.19kB 2
y-ononoMacBook-Pro:117 y_ono$
出力フォーマット
y-ononoMacBook-Pro:117 y_ono$ docker container ls --format='table {{.ID}}\t{{.Names}}\t{{.Ports}}'
CONTAINER ID NAMES PORTS
4bcc414f095f zen_jepsen 0.0.0.0:8090->80/tcp
b6117d59c282 mynginx 0.0.0.0:8081->80/tcp
y-ononoMacBook-Pro:117 y_ono$
y-ononoMacBook-Pro:117 y_ono$ docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4bcc414f095f nginx "/docker-entrypoint.…" 2 hours ago Up 2 hours 0.0.0.0:8090->80/tcp zen_jepsen
b6117d59c282 nginx "/docker-entrypoint.…" 2 hours ago Up 2 hours 0.0.0.0:8081->80/tcp mynginx
y-ononoMacBook-Pro:117 y_ono$ docker container stop zen_jepsen
zen_jepsen
y-ononoMacBook-Pro:117 y_ono$ docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4bcc414f095f nginx "/docker-entrypoint.…" 2 hours ago Exited (0) About a minute ago zen_jepsen
b6117d59c282 nginx "/docker-entrypoint.…" 2 hours ago Up 2 hours 0.0.0.0:8081->80/tcp mynginx
再開
y-ononoMacBook-Pro:117 y_ono$ docker container start zen_jepsen
zen_jepsen
y-ononoMacBook-Pro:117 y_ono$ docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4bcc414f095f nginx "/docker-entrypoint.…" 2 hours ago Up 5 seconds 0.0.0.0:8090->80/tcp zen_jepsen
b6117d59c282 nginx "/docker-entrypoint.…" 2 hours ago Up 2 hours 0.0.0.0:8081->80/tcp mynginx
y-ononoMacBook-Pro:117 y_ono$
y-ononoMacBook-Pro:117 y_ono$ docker container rm zen_jepsen
zen_jepsen
y-ononoMacBook-Pro:117 y_ono$
永続化データも消えるので絶対しない
- publicイメージ
- localイメージ
- コンテナ
y-ononoMacBook-Pro:117 y_ono$ docker search python
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
python Python is an interpreted, interactive, objec… 5614 [OK]
django Django is a free web application framework, … 1007 [OK]
pypy PyPy is a fast, compliant alternative implem… 253 [OK]
joyzoursky/python-chromedriver Python with Chromedriver, for running automa… 54 [OK]
nikolaik/python-nodejs Python with Node.js 54 [OK]
arm32v7/python Python is an interpreted, interactive, objec… 53
circleci/python Python is an interpreted, interactive, objec… 41
centos/python-35-centos7 Platform for building and running Python 3.5… 38
centos/python-36-centos7 Platform for building and running Python 3.6… 30
hylang Hy is a Lisp dialect that translates express… 28 [OK]
arm64v8/python Python is an interpreted, interactive, objec… 23
centos/python-27-centos7 Platform for building and running Python 2.7… 17
bitnami/python Bitnami Python Docker Image 10 [OK]
publicisworldwide/python-conda Basic Python environments with Conda. 6 [OK]
dockershelf/python Repository for docker images of Python. Test… 5 [OK]
clearlinux/python Python programming interpreted language with… 4
d3fk/python_in_bottle Simple python:alpine completed by Bottle+Req… 4 [OK]
i386/python Python is an interpreted, interactive, objec… 3
komand/python-plugin DEPRECATED: Komand Python SDK 2 [OK]
centos/python-34-centos7 Platform for building and running Python 3.4… 2
ppc64le/python Python is an interpreted, interactive, objec… 2
amd64/python Python is an interpreted, interactive, objec… 1
ccitest/python CircleCI test images for Python 0 [OK]
s390x/python Python is an interpreted, interactive, objec… 0
saagie/python Repo for python jobs 0
y-ononoMacBook-Pro:117 y_ono$
y-ononoMacBook-Pro:117 y_ono$ docker search -f "is-official=true" -f "stars=50" python
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
python Python is an interpreted, interactive, objec… 5614 [OK]
django Django is a free web application framework, … 1007 [OK]
pypy PyPy is a fast, compliant alternative implem… 253 [OK]
y-ononoMacBook-Pro:117 y_ono$
y-ononoMacBook-Pro:117 y_ono$ docker pull python:3.7.5-slim
3.7.5-slim: Pulling from library/python
000eee12ec04: Pull complete
ddc2d83f8229: Pull complete
735b0bee82a3: Pull complete
8c69dcedfc84: Pull complete
495e1cccc7f9: Pull complete
Digest: sha256:59af1bb7fb92ff97c9a23abae23f6beda13a95dbfd8100c7a2f71d150c0dc6e5
Status: Downloaded newer image for python:3.7.5-slim
docker.io/library/python:3.7.5-slim
3.7.5-slim: Pulling from library/python
Digest: sha256:59af1bb7fb92ff97c9a23abae23f6beda13a95dbfd8100c7a2f71d150c0dc6e5
Status: Image is up to date for python:3.7.5-slim
docker.io/library/python:3.7.5-slim
y-ononoMacBook-Pro:117 y_ono$
y-ononoMacBook-Pro:117 y_ono$ docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest c39a868aad02 45 hours ago 133MB
uims-portal_app latest 4368b223c77d 3 days ago 882MB
uims-api_api latest 803bc652df0e 2 months ago 1.18GB
node 14.4.0-stretch-slim 0e2e78467169 5 months ago 165MB
hello-world latest bf756fb1ae65 10 months ago 13.3kB
python 3.7.5-slim 9f4008bf3f11 11 months ago 178MB
oiax/rails6-deps latest 68b3321c4f66 13 months ago 334MB
ruby 2.6.3 8fe6e1f7b421 15 months ago 840MB
postgres 11.2-alpine cd1fb3df8252 18 months ago 70.8MB
ruby 2.5.3 72aaaee1eea4 20 months ago 873MB
ruby 2.5.1 3c8181e703d2 2 years ago 869MB
nginx 1.14.0 ecc98fc2f376 2 years ago 109MB
mariadb 10.3.8 2c73b3262fff 2 years ago 363MB
node 8.11.3 ed145ef978c4 2 years ago 673MB
ruby 2.4.0 6ec7e9c998da 3 years ago 681MB
y-ononoMacBook-Pro:117 y_ono$
y-ononoMacBook-Pro:117 y_ono$ docker image inspect python:3.7.5-slim
[
{
"Id": "sha256:9f4008bf3f119728447a7112ff04e016d8eb756158525ffec07c7f2e4e80cf90",
"RepoTags": [
"python:3.7.5-slim"
],
"RepoDigests": [
"python@sha256:59af1bb7fb92ff97c9a23abae23f6beda13a95dbfd8100c7a2f71d150c0dc6e5"
],
"Parent": "",
"Comment": "",
"Created": "2019-11-23T06:13:06.996726463Z",
"Container": "d4b8fa53d5780c03274b6f39087a1d5c56523eb428ed523d2e967b0fe3029367",
"ContainerConfig": {
"Hostname": "d4b8fa53d578",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"LANG=C.UTF-8",
"GPG_KEY=0D96DF4D4110E5C43FBFB17F2D347EA6AA65421D",
"PYTHON_VERSION=3.7.5",
"PYTHON_PIP_VERSION=19.3.1",
"PYTHON_GET_PIP_URL=https://github.com/pypa/get-pip/raw/ffe826207a010164265d9cc807978e3604d18ca0/get-pip.py",
"PYTHON_GET_PIP_SHA256=b86f36cc4345ae87bfd4f10ef6b2dbfa7a872fbff70608a1e43944d283fd0eee"
],
"Cmd": [
"/bin/sh",
"-c",
"#(nop) ",
"CMD [\"python3\"]"
],
"ArgsEscaped": true,
"Image": "sha256:62d1bf5a3803ce220f72a7bce573128e95cfe9b0b73f9c1d0fcce304a8cddf74",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": {}
},
"DockerVersion": "18.06.1-ce",
"Author": "",
"Config": {
"Hostname": "",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"LANG=C.UTF-8",
"GPG_KEY=0D96DF4D4110E5C43FBFB17F2D347EA6AA65421D",
"PYTHON_VERSION=3.7.5",
"PYTHON_PIP_VERSION=19.3.1",
"PYTHON_GET_PIP_URL=https://github.com/pypa/get-pip/raw/ffe826207a010164265d9cc807978e3604d18ca0/get-pip.py",
"PYTHON_GET_PIP_SHA256=b86f36cc4345ae87bfd4f10ef6b2dbfa7a872fbff70608a1e43944d283fd0eee"
],
"Cmd": [
"python3"
],
"ArgsEscaped": true,
"Image": "sha256:62d1bf5a3803ce220f72a7bce573128e95cfe9b0b73f9c1d0fcce304a8cddf74",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": null
},
"Architecture": "amd64",
"Os": "linux",
"Size": 178498345,
"VirtualSize": 178498345,
"GraphDriver": {
"Data": {
"LowerDir": "/var/lib/docker/overlay2/8d826e873f17aba4c2da7927482f6e61906e5a63146fe9d71d6d43de3aa1a060/diff:/var/lib/docker/overlay2/150c63e1d2e6a0ed87ffe2278ed7330fa6d6bfc649781eabc4b03260503e44ad/diff:/var/lib/docker/overlay2/e59955f15c62e3845cd38a43b44d3de85a57d3e1705978f7915db0032e9e21c9/diff:/var/lib/docker/overlay2/d2816e09abafbfbcf6094f68faabddb963bd5d2899fc0c1d874c153ebea12fca/diff",
"MergedDir": "/var/lib/docker/overlay2/68806423348b21caebb9b3a00864445adbf8080acae2c3aa121d26b83c567ed9/merged",
"UpperDir": "/var/lib/docker/overlay2/68806423348b21caebb9b3a00864445adbf8080acae2c3aa121d26b83c567ed9/diff",
"WorkDir": "/var/lib/docker/overlay2/68806423348b21caebb9b3a00864445adbf8080acae2c3aa121d26b83c567ed9/work"
},
"Name": "overlay2"
},
"RootFS": {
"Type": "layers",
"Layers": [
"sha256:831c5620387fb9efec59fc82a42b948546c6be601e3ab34a87108ecf852aa15f",
"sha256:459d9d53a2569cce05f289f8a7b84bf14e0d160aef722169e792743130fc6c53",
"sha256:ca56b6fe98b719be763ba1c978f2fe1a1c6b14a5d4b7c867f8e6b2fdbb5bd63e",
"sha256:870ea4318145741ea160b4661210d101273d51c807e5a23b0a087b464438cfc9",
"sha256:36c21e8952307685df69802fc94b1b75dbcb70a2e8465c97cb9c56a828e3615a"
]
},
"Metadata": {
"LastTagTime": "0001-01-01T00:00:00Z"
}
}
]
y-ononoMacBook-Pro:117 y_ono$
y-ononoMacBook-Pro:117 y_ono$ docker rm hello1
hello1
y-ononoMacBook-Pro:117 y_ono$
コンテナ削除
docker prune -f
- イメージからコンテナの起動
- コンテナ内でflaskのインストール
- アプリサーバのコードを手元からコンテナにコピー
- コンテナでアプリサーバの起動
- コンテナのイメージか
- イメージにユーザ名とタグを加えて改名
- 改名したイメージをレジストリに登録
y-ononoMacBook-Pro:117 y_ono$ docker container run --name base -it -p 8080:80 python:3.7.5-slim bash
root@3d1d9602fd01:/# pip install flask==1.1.1
Collecting flask==1.1.1
Downloading https://files.pythonhosted.org/packages/9b/93/628509b8d5dc749656a9641f4caf13540e2cdec85276964ff8f43bbb1d3b/Flask-1.1.1-py2.py3-none-any.whl (94kB)
|████████████████████████████████| 102kB 423kB/s
Collecting itsdangerous>=0.24
Downloading https://files.pythonhosted.org/packages/76/ae/44b03b253d6fade317f32c24d100b3b35c2239807046a4c953c7b89fa49e/itsdangerous-1.1.0-py2.py3-none-any.whl
Collecting Werkzeug>=0.15
Downloading https://files.pythonhosted.org/packages/cc/94/5f7079a0e00bd6863ef8f1da638721e9da21e5bacee597595b318f71d62e/Werkzeug-1.0.1-py2.py3-none-any.whl (298kB)
|████████████████████████████████| 307kB 829kB/s
Collecting click>=5.1
Downloading https://files.pythonhosted.org/packages/d2/3d/fa76db83bf75c4f8d338c2fd15c8d33fdd7ad23a9b5e57eb6c5de26b430e/click-7.1.2-py2.py3-none-any.whl (82kB)
|████████████████████████████████| 92kB 978kB/s
Collecting Jinja2>=2.10.1
Downloading https://files.pythonhosted.org/packages/30/9e/f663a2aa66a09d838042ae1a2c5659828bb9b41ea3a6efa20a20fd92b121/Jinja2-2.11.2-py2.py3-none-any.whl (125kB)
|████████████████████████████████| 133kB 920kB/s
Collecting MarkupSafe>=0.23
Downloading https://files.pythonhosted.org/packages/98/7b/ff284bd8c80654e471b769062a9b43cc5d03e7a615048d96f4619df8d420/MarkupSafe-1.1.1-cp37-cp37m-manylinux1_x86_64.whl
Installing collected packages: itsdangerous, Werkzeug, click, MarkupSafe, Jinja2, flask
Successfully installed Jinja2-2.11.2 MarkupSafe-1.1.1 Werkzeug-1.0.1 click-7.1.2 flask-1.1.1 itsdangerous-1.1.0
WARNING: You are using pip version 19.3.1; however, version 20.2.4 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
root@3d1d9602fd01:/#
y-ononoMacBook-Pro:117 y_ono$ ls
server.py
y-ononoMacBook-Pro:117 y_ono$ docker container cp server.py base:/
y-ononoMacBook-Pro:117 y_ono$
root@3d1d9602fd01:/# ls /
bin boot dev etc home lib lib64 media mnt opt proc root run sbin server.py srv sys tmp usr var
root@3d1d9602fd01:/# python -u /server.py
* Serving Flask app "app server" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: on
* Running on http://0.0.0.0:80/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger PIN: 273-489-757
y-ononoMacBook-Pro:117 y_ono$ docker container cp base:/etc/hosts ./
y-ononoMacBook-Pro:117 y_ono$ cat hosts
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.17.0.3 3d1d9602fd01
y-ononoMacBook-Pro:117 y_ono$
root@3d1d9602fd01:/# python -u /server.py
* Serving Flask app "app server" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: on
* Running on http://0.0.0.0:80/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger PIN: 273-489-757
^Croot@3d1d9602fd01:/exit
exit
y-ononoMacBook-Pro:117 y_ono$
y-ononoMacBook-Pro:117 y_ono$ docker container commit base c2img1_app
sha256:84d1c63117c4add3f4212ebdfc939b42776bda4a69fafabbffb8026c51523de0
y-ononoMacBook-Pro:117 y_ono$ docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
c2img1_app latest 84d1c63117c4 11 seconds ago 188MB
nginx latest c39a868aad02 3 days ago 133MB
uims-portal_app latest 4368b223c77d 4 days ago 882MB
uims-api_api latest 803bc652df0e 2 months ago 1.18GB
node 14.4.0-stretch-slim 0e2e78467169 5 months ago 165MB
hello-world latest bf756fb1ae65 10 months ago 13.3kB
python 3.7.5-slim 9f4008bf3f11 11 months ago 178MB
oiax/rails6-deps latest 68b3321c4f66 13 months ago 334MB
ruby 2.6.3 8fe6e1f7b421 15 months ago 840MB
postgres 11.2-alpine cd1fb3df8252 18 months ago 70.8MB
ruby 2.5.3 72aaaee1eea4 20 months ago 873MB
ruby 2.5.1 3c8181e703d2 2 years ago 869MB
nginx 1.14.0 ecc98fc2f376 2 years ago 109MB
mariadb 10.3.8 2c73b3262fff 2 years ago 363MB
node 8.11.3 ed145ef978c4 2 years ago 673MB
ruby 2.4.0 6ec7e9c998da 3 years ago 681MB
y-ononoMacBook-Pro:117 y_ono$ docker container run --rm -p 8080:80 c2img1_app python -u /server.py
* Serving Flask app "app server" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: on
* Running on http://0.0.0.0:80/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger PIN: 952-802-701
y-ononoMacBook-Pro:117 y_ono$ docker image history c2img1_app
IMAGE CREATED CREATED BY SIZE COMMENT
84d1c63117c4 3 minutes ago bash 9.51MB
9f4008bf3f11 11 months ago /bin/sh -c #(nop) CMD ["python3"] 0B
<missing> 11 months ago /bin/sh -c set -ex; savedAptMark="$(apt-ma… 7.42MB
<missing> 11 months ago /bin/sh -c #(nop) ENV PYTHON_GET_PIP_SHA256… 0B
<missing> 11 months ago /bin/sh -c #(nop) ENV PYTHON_GET_PIP_URL=ht… 0B
<missing> 11 months ago /bin/sh -c #(nop) ENV PYTHON_PIP_VERSION=19… 0B
<missing> 11 months ago /bin/sh -c cd /usr/local/bin && ln -s idle3… 32B
<missing> 11 months ago /bin/sh -c set -ex && savedAptMark="$(apt-… 94.8MB
<missing> 11 months ago /bin/sh -c #(nop) ENV PYTHON_VERSION=3.7.5 0B
<missing> 11 months ago /bin/sh -c #(nop) ENV GPG_KEY=0D96DF4D4110E… 0B
<missing> 11 months ago /bin/sh -c apt-get update && apt-get install… 7.03MB
<missing> 11 months ago /bin/sh -c #(nop) ENV LANG=C.UTF-8 0B
<missing> 11 months ago /bin/sh -c #(nop) ENV PATH=/usr/local/bin:/… 0B
<missing> 11 months ago /bin/sh -c #(nop) CMD ["bash"] 0B
<missing> 11 months ago /bin/sh -c #(nop) ADD file:bc8179c87c8dbb3d9… 69.2MB
y-ononoMacBook-Pro:117 y_ono$
y-ononoMacBook-Pro:117 y_ono$ docker image tag c2img1_app y_ono/c2img1_app
y-ononoMacBook-Pro:117 y_ono$ docker image tag c2img1_app y_ono/c2img1_app:v1.0
y-ononoMacBook-Pro:117 y_ono$ docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
c2img1_app latest 84d1c63117c4 6 minutes ago 188MB
y_ono/c2img1_app latest 84d1c63117c4 6 minutes ago 188MB
y_ono/c2img1_app v1.0 84d1c63117c4 6 minutes ago 188MB
The push refers to repository [docker.io/y_ono/c2img1_app]
a4a183bbd3a1: Preparing
36c21e895230: Preparing
870ea4318145: Preparing
ca56b6fe98b7: Preparing
459d9d53a256: Preparing
831c5620387f: Waiting
denied: requested access to the resource is denied
y-ononoMacBook-Pro:117 y_ono$