Resources and commands for Docker.
MIT License
NOTE:
- Docker Desktop for Windows Home is here!
- For Win 10 Home (2004 and above), Pro and Enterprise, install Docker Desktop.
- For Win 10 Home 1909 and lower, install Docker Toolkit.
- Docker might not work on VSCode integrated terminal. In that case, open VSCode as an administrator, use ext cmd or use powershell.
- Some commands might not work in cmd. Use Powershell in that case.
$(pwd)
in MacOS is$(%cd%)
in Cmd and${PWD}
in Powershelllocalhost:port
might not work. Use198.168.99.100:port
instead.- Container privileges
Please refer to linux-networking.md.
docker version
docker info
docker images
docker image rm ed2
(the entire image ID is not required)docker pull nginx
docker image build -t harshkapadia/nginx-website .
harshkapadia/nginx-website
= Docker_ID/img_name.
= refering to Dockerfile in currect dir (make sure your cmd is pointing to the correct folder)docker push harshkapadia/nginx-website
docker container ls
docker container ps
docker ps
docker container ls -a
docker ps -a
docker container run -it -p 80:80 --name my_custom_name_for_nginx nginx
container
= management commandrun
= sub-commandit
= interactive terminal, ie, run in the foreground-p
or --publish
= publish80:80
= mapping ports (portto_be_used_on_local_machine(useany_port):port_exposed_from_container- (use_default_port_of_service_in_container))nginx
= image namelocalhost:80
or localhost
(default is 80) or 127.0.0.1
(localhost)192.168.99.100
(Since Toolbox is running a Linux VM in VirtualBox, localhost won't work. Use 192.168.99.100
(default) instead.)docker container run -d -p 8080:80 --name my_custom_name_for_nginx nginx
-d
or --detach
= detacheddocker stop my_custom_name_for_nginx
or docker container stop my_custom_name_for_nginx
192.168.99.100:8080
(Win 10 Home users - might not be needed with Docker Desktop - localhost
might work)docker container rm c699
(the entire container ID is not required) (deleting container does not remove the image from the system)docker container rm c699 -f
docker rm $(docker ps -aq) -f
(-f
added to remove any running container(s) as well) (this ran in powershell, but not in cmd)docker container run -d -p 3306:3306 --name my_sql_user --env MYSQL_ROOT_PASSWORD=123456 mysql
(you can find the env vars on Docker Hub)docker container run -d -p 80:80 --name custom_name_nginx nginx
docker start <container_id>
docker container exec -it mynginx bash
(start the container using the abv cmd before doing this)
ls
cd usr/share/nginx/html
exit
NOTE: Ports 80 or 8081 might not work with below example. Use 8080, 8082, 8083...
bind_mount.md
for further details on 'x_drive'.docker-machine start
)docker container run -d -p 8080:80 -v /x_drive/coding/docker/docker_basics/mounting_example:/usr/share/nginx/html --name - nginx-website nginx
mounting_example
folder.docker container run -it -v "%cd%":/mnt --name kali kalilinux/kali-rolling