Skip to content

NOTE20190725

Somkiat Puisungnoen edited this page Jul 26, 2019 · 2 revisions

Docker commands and resources

Manage image

// Download images
$docker image pull nginx:1.17.2
$docker image pull nginx:1.17.2-alpine
$docker image ls

// Remove all images
$docker image prune
$docker image rm $(docker image ls -q)

Manage container

// run with foreground mode
$docker container run nginx:1.17.2-alpine

// run with background mode
$docker container run -d nginx:1.17.2-alpine

// run and access to container
$docker container run -it nginx:1.17.2-alpine sh

// run with publish port to host
$docker container run -d -p <host port>:<container port> nginx:1.17.2-alpine
$docker container run -d -p 8000:80 nginx:1.17.2-alpine  // Specified port
$docker container run -d -P nginx:1.17.2-alpine // Random port [32768 to 65535]

// run with map volume to host
$docker container run -d -v <host path>:<container path> nginx:1.17.2-alpine

// run with specified default path in container (Working directory)
$docker container run -d -w <container path> nginx:1.17.2-alpine

// List of all containers
$docker container ps
$docker container ps -a
$docker container ps -a -q
$docker container inspect 8455437e6076

// Remove all containers
$docker container stop $(docker image ls -q)
$docker container prune

$docker container stop $(docker image ls -q)
$docker container rm $(docker image ls -a -q)

Access to container

$docker container exec -it 8455437e6076 sh
#ps

See diff of container

$docker container diff 8455437e6076

Save container to image

$docker container commit 8455437e6076 web:1.0
$docker image ls

Build image from Dockerfile

$docker image build -t xxx:1.0 -f Dockerfile .
$docker image ls

Docker

Resources

Clone this wiki locally