Introduction
Installation
https://docs.docker.com/engine/install/
Basics
Here we launch a container named "test" in "detached interactive terminal" so that it runs in the background, and we mount the local pagesweb folder in the /usr/usr/share/nginx container folder in read-only mode, finally using the official nginx image:
docker run βname test -dit -p 8080:80 -v ~/pagesweb:/usr/usr/share/nginx/html:ro nginx
-v :: OR --mount type=,src=folder1,dst=folder2
Dockerfile is used to build docker images (not containers), here is an example of Dockerfile
FROM debian:latest
LABEL maintainer="kp <info@kp.fr>"
RUN apt-get update \
&& apt-get install -y iputils-ping \
&& apt-get install -y traceroute \
&& apt-get install -y curl \
&& apt-get clean
CMD ["/usr/bin/bash"]
Build & Push Image
You need a free dockerhub account.
docker login --username yourmail@gmail.com
docker build -t you_username/your_image:latest .
docker push your_username/your_image:latest
sudo apt update
sudo apt install docker-compose-plugin
Usage
The docker compose command makes the creation of containers easy. You first need to create a compose.yaml file, here is an example :
Be Careful: Each Docker Volume/Network used need to be created in the compose file outside of services (level 0 of yaml), see the end of the example. By default all of the containers will be created in the same docker network.
services:
# MARIADB
:
image: mariadb:latest
environment:
MYSQL_RANDOM_ROOT_PASSWORD: 1
MYSQL_DATABASE: blog
MYSQL_USER: bloguser
MYSQL_PASSWORD: pass123
volumes:
- dbvol:/var/lib/mysql
networks:
- blognet
restart: always
# PHPMYADMIN
dbadmin:
image: phpmyadmin/phpmyadmin:latest
environment:
PMA_HOST: db
ports:
- 9090:80
networks:
- blognet
restart: always
# WORDPRESS
web:
image: wordpress:latest
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: bloguser
WORDPRESS_DB_PASSWORD: pass123
WORDPRESS_DB_NAME: blog
ports:
- 9000:80
networks:
- blognet
volumes:
- webvol:/var/www/html/wp-content
restart: always
volumes:
dbvol:
webvol:
networks:
blognet:
and run:
docker compose up
Examples
Run Docker Compose file:
docker compose up -d
Start all services:
docker compose up
Stop all services:
docker compose down
Last updated