Containers How To: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 17: | Line 17: | ||
* Check the Docker version: | * Check the Docker version: | ||
: '''docker --version''' | : '''docker --version''' | ||
* Pull and run '''“hello-world”''' image from Docker hub: | |||
docker run hello-world | : '''docker run hello-world''' | ||
* List images: | |||
docker images | : '''docker images''' | ||
* List all images: | |||
docker image ls | : '''docker image ls''' | ||
* Pull an image from Docker hub: | |||
docker image pull alpine | * '''docker image pull alpine'''' | ||
* Remove Docker image (by image name) from the local machine: | |||
docker image rm nginx | : '''docker image rm nginx''' | ||
* List all containers: | |||
docker container ls --all | : '''docker container ls --all''' | ||
* List active containers: | |||
docker ps | : '''docker ps''' | ||
* List all container processes (same as docker container ls command) | |||
docker ps --all | : '''docker ps --all''' | ||
* Pull nginx web server from Docker hub and run it on port 80 on the local machine: | |||
docker run --detach --publish 80:80 --name webserver nginx | : '''docker run --detach --publish 80:80 --name webserver nginx''' | ||
Note: Open browser and enter the URL http://localhost to make sure the web server is working | : Note: Open browser and enter the URL http://localhost to make sure the web server is working | ||
* Start a container in the background: | |||
docker run -d jenkins | : '''docker run -d jenkins''' | ||
* Start an interactive shell command from a container (by image name): | |||
docker run -it nginx bash | : '''docker run -it nginx bash''' | ||
* Mount a folder from the local machine into a docker container, and map port 8080 locally to port 80 on the container (container name nginx): | |||
docker run -v /full/path/to/html/directory:/usr/share/nginx/html:ro -p 8080:80 -d nginx | : '''docker run -v /full/path/to/html/directory:/usr/share/nginx/html:ro -p 8080:80 -d nginx''' | ||
* Stop running container (by container name) from the local machine: | |||
docker container stop webserver | : '''docker container stop webserver''' | ||
* Start (a stopped) docker container (by container name) on the local machine: | |||
docker container start webserver | : '''docker container start webserver''' | ||
* Kill all running containers: | |||
docker kill $(docker ps -q) | : '''docker kill $(docker ps -q)''' | ||
* Remove all stopped containers: | |||
docker rm $(docker ps -a -q) | : '''docker rm $(docker ps -a -q)''' | ||
* Remove container (by container name) from the local machine: | |||
docker container rm webserver | : '''docker container rm webserver''' | ||
* View logs from a running container (by container name): | |||
docker container logs webserver | : '''docker container logs webserver''' | ||
* Show live logs of running container: | |||
docker logs -f c7337 | : '''docker logs -f c7337''' | ||
* View top processes inside a container (by container name): | |||
docker container top webserver | : '''docker container top webserver''' | ||
* Show exposed ports of a container: | |||
docker port c7337 | : '''docker port c7337''' |
Revision as of 13:51, 10 June 2019
How to install Docker (Windows Platform)
- Login to the machine using privileged account
- Download the latest Docker build from:
How to install Docker (Ubuntu)
- Login to the machine using privileged account
- Follow the instructions below:
How to install Docker (RHEL / CentOS)
- Login to the machine using privileged account
- Follow the instructions below:
Common Docker commands
- Check the Docker version:
- docker --version
- Pull and run “hello-world” image from Docker hub:
- docker run hello-world
- List images:
- docker images
- List all images:
- docker image ls
- Pull an image from Docker hub:
- docker image pull alpine'
- Remove Docker image (by image name) from the local machine:
- docker image rm nginx
- List all containers:
- docker container ls --all
- List active containers:
- docker ps
- List all container processes (same as docker container ls command)
- docker ps --all
- Pull nginx web server from Docker hub and run it on port 80 on the local machine:
- docker run --detach --publish 80:80 --name webserver nginx
- Note: Open browser and enter the URL http://localhost to make sure the web server is working
- Start a container in the background:
- docker run -d jenkins
- Start an interactive shell command from a container (by image name):
- docker run -it nginx bash
- Mount a folder from the local machine into a docker container, and map port 8080 locally to port 80 on the container (container name nginx):
- docker run -v /full/path/to/html/directory:/usr/share/nginx/html:ro -p 8080:80 -d nginx
- Stop running container (by container name) from the local machine:
- docker container stop webserver
- Start (a stopped) docker container (by container name) on the local machine:
- docker container start webserver
- Kill all running containers:
- docker kill $(docker ps -q)
- Remove all stopped containers:
- docker rm $(docker ps -a -q)
- Remove container (by container name) from the local machine:
- docker container rm webserver
- View logs from a running container (by container name):
- docker container logs webserver
- Show live logs of running container:
- docker logs -f c7337
- View top processes inside a container (by container name):
- docker container top webserver
- Show exposed ports of a container:
- docker port c7337