devops:docker
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
devops:docker [2018/01/11 12:16] – [Host to Container connectivity] skipidar | devops:docker [2025/03/22 23:03] (current) – skipidar | ||
---|---|---|---|
Line 34: | Line 34: | ||
== Commands == | == Commands == | ||
- | ^ Command | + | ^ Command |
- | | commit | creates a new image from a container | | + | | commit |
- | | run | runs a container from an image | | + | | run |
- | | start | starts an EXISTING, STOPPED container | | + | | start |
- | | stop | stops an EXISTING, RUINNING container | | + | | stop | stops an EXISTING, RUINNING container |
- | | exec | executes a command INSIDE of EXISTING, RUNNING container | | + | | exec | executes a command INSIDE of EXISTING, RUNNING container |
- | | docker search NAME | Search for an image with the specified name. | | + | | docker search NAME | Search for an image with the specified name. |
- | | docker pull NAME | Pull an image into your local file system with he specified name. | | + | | docker pull NAME | Pull an image into your local file system with he specified name. | |
- | | docker version | Prints the docker version to the standard output. | | + | | docker version |
- | | docker run -td -p 80:8080 NAME | Run a docker image with daemon mode with port 80 forwarded to port 8080 in the container. | | + | | docker run -td -p 80:8080 NAME | Run a docker image with daemon mode with port 80 forwarded to port 8080 in the container. |
- | | docker start CONTAINERID | Start a stopped container. | | + | | docker start CONTAINERID |
- | | docker stop CONTAINERID | Stop a container with the specified id. | | + | | docker stop CONTAINERID |
- | | docker ps | List all RUNNING container | | + | | docker ps |
- | | docker ps -a | List all container | | + | | docker ps -a | List all container |
- | | docker login -u USERNAME -p PASSWORD -e EMAIL registryURL | Login to a registry with -u for username -p for password and -e for email. | | + | | docker login -u USERNAME -p PASSWORD -e EMAIL registryURL |
- | | docker rm CONTAINERID | Remove a container. | | + | | docker rm CONTAINERID |
- | | docker images -a | list all images | | + | | docker images -a | list all images |
- | | docker rmi IMAGEID | Remove an image. | | + | | docker rmi IMAGEID |
- | | docker logs | Fetch the logs from a docker container. | | + | | docker logs |
- | | docker inspect IMAGE_NAME|echo JSON with describtion| | + | | docker inspect IMAGE_NAME |
- | | docker run -d IMAGE_NAME | Detach. Means run in background. Even when you quit the container. Dont block the console with STDOUT. | | + | | docker run -d IMAGE_NAME |
- | | docker run -P IMAGE_NAME | expose ports on DOCKER_HOST. Port 5000 of container is redirected to localhost: | + | | docker run -P IMAGE_NAME |
- | | docker exec -it CONTAINERID COMMAND |< | + | | docker exec -it CONTAINERID COMMAND |
- | You can find out the COMMAND available for CONTAINERID by doing //docker ps//. | + | | docker inspect CONTAINER_NAME |
- | < | + | | docker-machine ls |
- | $ docker ps | + | | docker-machine create --driver virtualbox HOSTNAME |
- | + | | docker-machine rm HOSTNAME | |
- | CONTAINER ID IMAGE | + | | docker-machine restart HOSTNAME |
- | NAMES | + | | < |
- | 625ad92a1f53 | + | | docker attach CONTAINERNAME |
- | + | | docker commit jira skipidar/ | |
- | $ docker exec -it 625ad92a1f53 "/ | + | | docker push skipidar/ |
- | </ | + | | docker exec < |
- | </ | + | | docker run --restart=always jenkinsci/ |
- | | docker inspect CONTAINER_NAME | Provide ALL data about the container. | | + | | docker top < |
- | | docker-machine ls | list existing hosts| | + | | docker stats | The resources consumed by docker |
- | | docker-machine create --driver virtualbox HOSTNAME| create host| | + | | docker container logs -f < |
- | | docker-machine rm HOSTNAME| remove host| | + | |
- | | docker-machine restart HOSTNAME| restarts the host| | + | |
- | | < | + | |
- | | docker attach CONTAINERNAME | Shows what is happening inside the container. You can even kill the process by CTRL+C | | + | |
- | | docker commit jira skipidar/ | + | |
- | | docker push skipidar/ | + | |
- | | docker exec < | + | |
- | < | + | |
- | PS D: | + | |
- | UID | + | |
- | root | + | |
- | root 130 0 0 16:29 ? 00:00:00 nginx: master process / | + | |
- | root 169 0 0 17:09 ? 00:00:00 ps -f | + | |
- | </ | + | |
- | + | ||
- | </ | + | |
- | | docker run --restart=always jenkinsci/ | + | |
Line 125: | Line 108: | ||
==== Setup on Windows ==== | ==== Setup on Windows ==== | ||
+ | |||
+ | === Using Docker Desktop === | ||
+ | The command & ' | ||
+ | |||
+ | < | ||
+ | & ' | ||
+ | </ | ||
+ | |||
+ | === Running containers | ||
+ | |||
+ | Example | ||
+ | < | ||
+ | docker run -it --gpus all -p 8080:8080 -v $HOME/ | ||
+ | | ||
+ | </ | ||
=== Using Windows native Hyper-V === | === Using Windows native Hyper-V === | ||
Line 681: | Line 679: | ||
So the IP Address of the docker host **172.17.42.1** is set as the default route and is accessible from your container. | So the IP Address of the docker host **172.17.42.1** is set as the default route and is accessible from your container. | ||
+ | |||
+ | |||
+ | ==== Docker Context ==== | ||
+ | The files/ | ||
+ | |||
+ | See https:// | ||
+ | |||
+ | You can explicitly create a tar.gz package and reference it during the build command. \\ | ||
+ | The tar ball has a flat hierarchy here, but may have any structure. Only, when referencing the files inside - one should consider this structure. | ||
+ | |||
+ | The DockerFile is referenced explicitely inside the tar.gz ball (**-f ./ | ||
+ | < | ||
+ | # create the context tar.gz | ||
+ | tar -C /vagrant -cvf / | ||
+ | |||
+ | # build the container with an existing gzipped context | ||
+ | docker build --no-cache -t runapp -f ./ | ||
+ | |||
+ | # run the container | ||
+ | docker run --name runAppContainer -d -p 8080:8080 runapp | ||
+ | </ | ||
+ | |||
+ | |||
+ | ==== Start bash in container as root ==== | ||
+ | If you would like to connect to the container MYCONTAINERNAME as root, | ||
+ | < | ||
+ | docker exec -it --user root MYCONTAINERNAME bash | ||
+ | < | ||
+ | |||
====== ADOP ====== | ====== ADOP ====== | ||
devops/docker.1515672987.txt.gz · Last modified: (external edit)