From d33fd494b3a9349eec5f623c7b20bbe9d743280b Mon Sep 17 00:00:00 2001 From: Ken Schaefer Date: Wed, 30 Nov 2022 09:17:16 -0600 Subject: [PATCH] more docker notes --- Cheatsheets/docker.md | 27 +++++++++++++++++++++++++-- Runbooks/docker-static-html-nginx.md | 3 ++- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/Cheatsheets/docker.md b/Cheatsheets/docker.md index 979d935..84d6426 100644 --- a/Cheatsheets/docker.md +++ b/Cheatsheets/docker.md @@ -114,11 +114,14 @@ Assign a name and tag to the image because you are not a barbarian. `docker images` ### Remove an image from this server +Can't remove images that have containers (started and stopped) `docker rmi {imagename}` ### Remove all dangling (untagged) images `docker image prune` +### Review detailed information about the image +`docker image inspect {imageid}` ## CONTAINERS @@ -141,7 +144,11 @@ After the image is built you will get an ID for the image. Use the ID to start t ## MANAGING CONTAINERS -Parameters for running a container +### Running a container +Get a list of all parameters for running a container +`docker run --help` + +Common parameters for running a container |Switch | Description | |-------|-------| |-p |(port) map a port| @@ -153,6 +160,10 @@ Parameters for running a container `docker run -p 3000:80 -d --rm --name goalsapp goals:latest` +Expose a terminal for console applications. See the Python example. +`docker run -it {containername}` +`docker start -a -i {containername}` + ### List all running containers `docker ps` @@ -163,9 +174,10 @@ Parameters for running a container `docker stop {containername}` ### Start a stopped container +This command will start a container in detached mode. `docker start {containername}` -### Remove a stopped container +### Remove a stopped container (can't remove a running container) `docker rm {containername}` ### Remove ALL stopped containers @@ -175,6 +187,17 @@ Parameters for running a container Use this if you are running in detached mode and need to attach to see content logged to the console. `docker attach {comtainername}` +### View logs from a container +logs are the console output from a container. This command will let you see the content. +`docker logs {containername}` + +### Copy files into or out of a running container +Copy in +`docker cp localpath/. {containername}:/pathincontainer` +Copy out +`docker cp {containername}:/pathincontainer/. localpath` + + ## Volumes Volumes store persistent data that survives after a container shuts down. These are folders on the host machine that are mounted in the container. diff --git a/Runbooks/docker-static-html-nginx.md b/Runbooks/docker-static-html-nginx.md index d065344..e590d33 100644 --- a/Runbooks/docker-static-html-nginx.md +++ b/Runbooks/docker-static-html-nginx.md @@ -13,10 +13,11 @@ EXPOSE 80 ``` ## Build the image +name:tag `docker build -t myproject:v1 .` ## Run a container from the image -`docker run -d -p 8080:80 myproject:v1` +`docker run -d -p 8080:80 --name myproject myproject:v1` ## View the site Open a browser at `http://localhost:8080` \ No newline at end of file