P
P
Pavel Finogentov2020-10-22 13:59:50
Docker
Pavel Finogentov, 2020-10-22 13:59:50

How to use docker volume if using docker image from dockerhub?

Deploying my project using docker compose. At the moment my project is being built locally, from local project folders. Docker uses Laravel service, VueJS service, NGINX service, Mysql service and Redis service.
I set up a docker compose file according to an article from digital ocean. The question is as follows. In the article, it was necessary to create volumes (volume) that linked my application files locally with container files, but what should I do if I want to build my project using dockerhub, because so, I will no longer store files locally.
I tried without these volumes in the backend and webserver, but then without any build errors, I cannot reach the server via localhost.
Do I just need to push the image along with the volume? Here is my compose.yml:


version: '3'
services:
#VueJS Service
frontend:
build: ./frontend
container_name: frontend
restart: unless-stopped
tty: true
environment:
SERVICE_NAME: frontend
working_dir: /var/www/frontend
ports:
- "3000:80"
volumes :
- ./frontend/:/var/www/frontend
- ./frontend/node_modules:/var/www/frontend/node_modules
networks:
- backend-network

#PHP Service
backend:
build: ./backend
container_name: backend
restart: unless -stopped
tty: true
environment:
SERVICE_NAME: backend
SERVICE_TAGS: dev
working_dir: /var/www
volumes:
- ./backend/:/var/www
- ./backend/php/local.ini:/usr/local/etc/php/conf.d/ local.ini
networks:
- backend-network

#Nginx Service
webserver:
image: nginx:alpine
container_name: webserver
restart: unless-stopped
tty: true
ports:
- "443:443"
- "8080:8080"
volumes:
- ./backend /:/var/www
- ./backend/nginx/conf.d/:/etc/nginx/conf.d/
networks:
- backend-network

#MySQL Service
db:
image: mysql:5.7.22
container_name: db
restart: unless-stopped
tty: true
ports:
- "33062:3306"
environment:
MYSQL_DATABASE: qcortex
MYSQL_ROOT_PASSWORD: kc3wcfjk5
SERVICE_TAGS: dev
SERVICE_NAME: mysql
volumes:
- dbdata: /var/lib/mysql
- ./backend/mysql/my.cnf : /etc/mysql/my.cnf
networks:
- backend-network

#Redis
redis:
image: caster977/redis
restart: unless-stopped
container_name: redis
networks:
- backend-network

#Docker Networks
networks:
backend-network:
driver: bridge

#Volumes
volumes:
dbdata:
driver: local

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
mureevms, 2020-10-22
@Caster97

what should I do if I want to build my project using dockerhub

Just create a dbdata directory and forward it to the container, refusing volumes:
db:
  image: mysql:5.7.22
   <...>
  volumes:
    - ./dbdata:/var/lib/mysql
    - ./backend/mysql/my.cnf:/etc/mysql/my.cnf

I can't reach the server via localhost

Not related to volumes, look for reasons in the docker-compose configuration

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question