docker container run -it -p 80:80 nginxdocker container run -d -p 80:80 nginxdocker container run -d -p 80:80 nginxdocker container run -d -p 80:80 --name nginx-server nginx- Looked for an image called
nginxin the image cache - If not found in cache, it looks to the default image repo on Docker Hub
- Pulled it down (latest version), stored in the image cache
- Started it in a new container
- Specified to take port 80 on the host and forward to port 80 on the container
- Could use
docker container run --publish 8000:80 --detach nginxto use port 8000 - Can specify versions like
nginx:1.09
docker container lsor
docker psdocker container ls -adocker 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]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'll need to connect directly to that. On Linux, however, you can run ps aux and see the processes directly.
docker image lsdocker pull [IMAGE]docker image rm [IMAGE]docker rmi $(docker images -a -q)- Images are app binaries and dependencies with metadata about the image data and how to run the image.
- Images are not a complete OS. No kernel, kernel modules (drivers).
- The host provides the kernel, a big difference between VMs.
NGINX:
docker container run -d -p 80:80 --name nginx nginx(Note: -p 80:80 is optional as it runs on 80 by default)
APACHE:
docker container run -d -p 8080:80 --name apache httpdMONGODB:
docker container run -d -p 27017:27017 --name mongo mongoMYSQL:
docker container run -d -p 3306:3306 --name mysql --env MYSQL_ROOT_PASSWORD=123456 mysqldocker container inspect [NAME]docker container inspect --format '{{ .NetworkSettings.IPAddress }}' [NAME]docker container stats [NAME]docker container run -it --name [NAME] nginx bashi= interactive: Keep STDIN open if not attachedt= tty: Open prompt
For Git Bash, use "winpty"
winpty docker container run -it --name [NAME] nginx bashdocker container run -it --name ubuntu ubuntu(Note: no bash because Ubuntu uses bash by default)
docker container run --rm -it --name [NAME] ubuntudocker container start -ai ubuntudocker container exec -it mysql bashdocker container run -it alpine sh(Note: use sh because it does not include bash. Alpine uses apk for its package manager - can install bash if you want)
In order to limit the amount of memory a Docker container process can use, simply set the -m [memory amount] flag with the limit.
To run a container with memory limited to 256 MBs:
docker run -m 64m -d -p 8082:80 tutum/wordpressdocker container port [NAME]docker network lsdocker network inspect [NETWORK_NAME](Note: "bridge" is default)
docker network create [NETWORK_NAME]or
docker network create --driver bridge [NETWORK_NAME]docker run -d --net=[NETWORK_NAME] --name mongodb mongodocker container run -d --name [NAME] --network [NETWORK_NAME] nginxdocker network connect [NETWORK_NAME] [CONTAINER_NAME]docker network disconnect [NETWORK_NAME] [CONTAINER_NAME]docker network disconnectTo remove the network by name or id, multiple can be deleted:
docker network rm [NETWORK_NAME] [NETWORK_NAME]docker image lsYou'll see that each image has a tag.
docker image tag nginx btraversy/nginxdocker image push bradtraversy/nginxdocker logindocker image tag bradtraversy/nginx bradtraversy/nginx:testingFROM- The OS used. Common is alpine, debian, ubuntu.ENV- Environment variables.RUN- Run commands/shell scripts, etc.EXPOSE- Ports to expose.CMD- Final command run when you launch a new container from image.WORKDIR- Sets working directory (also could useRUN cd /some/path).COPY- Copies files from host to container.
From the same directory as Dockerfile:
docker image build -t [REPONAME] .DOCKER_BUILDKIT=1 docker image build -t [REPONAME] .- If you re-run the build, it will be quick because everything is cached.
- If you change one line and re-run, that line and everything after will not be cached.
- Keep things that change the most toward the bottom of the Dockerfile.
FROM nginx:latest # Extends nginx so everything included in that image is included here
WORKDIR /usr/share/nginx/html
COPY index.html index.htmldocker image build -t nginx-websitedocker container run -p 80:80 --rm nginx-websitedocker image tag nginx-website:latest btraversy/nginx-website:latest
docker image push bradtraversy/nginx-websitedocker volume lsdocker volume prunedocker pull mysql