Simple setting to dealing with Dockerfile and docker-compose
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg \
Lsb-release
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
- how to search a docker image in hub.docker.com
docker search httpd
- Download a docker image from hub.docker.com
docker image pull <image_name>:<image_version/tag>
- Show all docker images on your local system
docker image
- Build docker image from Dockerfile
docker build -t <image_name> . #the dot in the end specify the current directory where the Dockerfile is located
- Create a docker container from image
docker run --name <container_Name> <image_name>:<image_version/tag>
docker - run your container in back ground (detached)
docker run -d --name <container_Name> <image_name>:<image_version/tag>
- Expose your application to host server
docker run -d --name <container_Name> -p <host_port>:<container_port> <image_name>:<Image_version/tag>
docker run -d --name httpd_container -p 8080:80 httpd:latest
- Show all running containers
docker ps
- Show all docker container (running, stpooed, terminated, etc...)
docker ps -a
- Get inside a container
docker exec -it <container_Name> bash
- Stop a container
docker stop <container_id>
- Start a container which is stopped
docker start <container_id>
- Remove a container
docker rm <container_id>
- Remove docker image
docker rmi <image_id>
Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image.
Docker compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML
file to configure your application's services. Then, with a single command, you create and start all the services from your configuration.