Workshop 1: Storage and Networks in Docker
Workshop 1: Storage and Networks in Docker
Storage
Let’s work with Docker volumes:
Create a Docker volume called “miweb”:
docker volume create miwebCreate a container from the image
php:7.4-apache, mounting the Docker volume in/var/www/html(the DocumentRoot of the server):docker run -d --name my-apache-app -v miweb:/var/www/html -p 8080:80 php:7.4-apacheUse the
docker cpcommand to copy anindex.htmlfile (with your name) into/var/www/html:echo "<h1>Javier Cruces</h1>" > index.html docker cp index.html my-apache-app:/var/www/html/Access the container from the browser to check the
index.htmlfile:curl http://localhost:8080Output:
<h1>Javier Cruces</h1>Delete the container:
docker rm -f my-apache-appCreate a new container and mount the same volume:
docker run -d --name Taller1 -v miweb:/var/www/html -p 8080:80 php:7.4-apacheAccess the container again to verify the file is still there:
curl http://localhost:8080Output:
<h1>Javier Cruces</h1>
Bind Mount
Create a directory on your host and copy
index.htmlinto it:mkdir taller1 cp index.html taller1/Create a container from
php:7.4-apache, mounting the directory via bind mount:docker run -d --name Taller1 -v $(pwd)/taller1:/var/www/html -p 8080:80 php:7.4-apacheAccess the container from the browser to verify the file:
curl http://localhost:8080Output:
<h1>Javier Cruces</h1>Modify the
index.htmlfile on your host and check if the content updates in the container:echo "<h1>Javier Cruces Doval</h1>" > taller1/index.html curl http://localhost:8080Output:
<h1>Javier Cruces Doval</h1>Delete the container:
docker rm -f Taller1Create a new container and mount the same directory:
docker run -d --name Taller1 -v $(pwd)/taller1:/var/www/html -p 8080:80 php:7.4-apacheVerify the content again:
curl http://localhost:8080Output:
<h1>Javier Cruces Doval</h1>
Networks
Nextcloud + MariaDB Deployment
We are going to deploy the Nextcloud application with a database (NOTE: Use the image mariadb:10.5 to avoid issues). You can use the WordPress deployment guide as reference.
Create a bridge-type network:
docker network create taller1Create the database container connected to the network. Configure it to create a database and a user, and ensure data persistence using volumes:
docker run -d --name wp_db \ --network taller1 \ -v db_vol:/var/lib/mysql \ -e MYSQL_ROOT_PASSWORD=wordpress \ -e MYSQL_DATABASE=wordpress \ -e MYSQL_USER=wordpress \ -e MYSQL_PASSWORD=wordpress \ mariadb:10.5Create a Nextcloud container connected to the same network, using appropriate environment variables for database connection and persistence:
docker run -d --name nextcloud \ --network taller1 \ -e MYSQL_DATABASE=wordpress \ -e MYSQL_USER=wordpress \ -e MYSQL_PASSWORD=wordpress \ -e MYSQL_HOST=wp_db \ -p 8080:80 \ nextcloud:latestAccess the application using a web browser at
http://localhost:8080.
