Skip to content

Latest commit

 

History

History
56 lines (47 loc) · 1.49 KB

File metadata and controls

56 lines (47 loc) · 1.49 KB

Docker Tutorial 🐳

I wrote this tutorial to expand my understanding of some of the more advanced functionality available in Docker. I have found that most tutorials try to overcomplicate this stuff with unnecessary requirements. In an attempt to alleviate the aforementioned problem, this tutorial uses a very simple React frontend and a very simple Express backend to demonstrate the use of a bridge network and a shared volume.

Create a Bridge Network

docker network create my_net
docker network ls

Create a Shared Volume

docker volume create --name DataVolume
docker volume ls

Build the Images

docker build -t backend:app backend/
docker build -t frontend:app frontend/
docker images

Run the Containers and Mount the Backend to the Shared Volume

docker run --network my_net --name backend -d -v DataVolume:/datavolume -p 3010:3010 backend:app
docker run --network my_net --name frontend -d  -p 3009:3009 frontend:app
docker ps

Add a File in the Shared Volume to be Read in the Backend

docker exec -it backend bash 
root@21a11dbd9a11:/usr/src/app# echo "990 991 992 993 994 995" >> /datavolume/data.txt
root@21a11dbd9a11:/usr/src/app# cat /datavolume/data.txt
root@21a11dbd9a11:/usr/src/app# exit

Restart the Backend

docker restart backend

Make Requests

curl http://localhost:3010/get_backend_data
curl http://localhost:3009/get_data

Check the Logs to View the Outputs

docker logs frontend
docker logs backend