$ docker version
$ docker info
Docker containers are often compared to virtual machines but they are actually just processes running on your host os. In Windows/Mac, Docker runs in a mini-VM so to see the processes you will need to connect directly to that. On Linux run "ps aux" and see the processes directly.
$ docker container run -it -p 80:80 nginx
$ docker container run -d -p 80:80 nginx
$ docker container run -d -p 80:80 --name nginx-server nginx
- Looked for image called nginx in image cache
- If not found in cache, it looks to the default image repo on Dockerhub
- Pulled it down (latest version), stored in the image cache
- Started it in a new container
- We specified to take port 80- on the host and forward to port 80 on the container
- We can specify versions like "nginx:1.09"
$ docker container ls
$ docker container ls -a
$ docker container stop <ID>
$ docker stop $(docker ps -aq)
$ docker container rm <ID>
$ docker container rm -f <ID>
$ docker container rm <ID> <ID> <ID>
$ docker rm $(docker ps -aq)
$ docker container logs <NAME>
$ docker container top <NAME>
- Images are app bianaries and dependencies with meta data about the image data and how to run the image
- Images are no a complete OS. No kernel, kernel modules (drivers)
- Host provides the kernel, big difference between VM
$ docker image ls
$ docker pull <image>
$ docker image rm <image>
$ docker rmi $(docker images -a -q)
NGINX:
$ docker container run -d -p 80:80 --name nginx nginx (-p 80:80 is optional as it runs on 80 by default)
APACHE:
$ docker container run -d -p 8080:80 --name apache httpd
MONGODB:
$ docker container run -d -p 27017:27017 --name mongo mongo
MYSQL:
$ docker container run -d -p 3306:3306 --name mysql --env MYSQL_ROOT_PASSWORD=123456 mysql
$ docker container inspect <NAME>
$ docker container inspect --format '{{ .NetworkSettings.IPAddress }}' <NAME>
$ docker container stats <NAME>
$ docker container run -it --name <NAME> nginx bash
- i = interactive Keep STDIN open if not attached
- t = tty - Open prompt
$ docker container run -it --name ubuntu ubuntu
(no bash because ubuntu uses bash by default)
$ docker container run --rm -it --name <NAME> ubuntu
$ docker container start -ai ubuntu
$ docker container exec -it mysql bash