The services are named equally because those are two equal projects...
When I do:
docker-compose -f infra/local/docker-compose.yml ps
It would show me containers from the other project:
jorgee#jorgee:~/Desktop/Proyectos/sss/sss_api_mx$ docker-compose -f ./infra/local/docker-compose.yml ps
Name Command State Ports
-------------------------------------------------------------------------------------------------------------
sss-mysql docker-entrypoint.sh mysqld Up 0.0.0.0:8081->3306/tcp,:::8081->3306/tcp, 33060/tcp
sss-php-fpm /usr/sbin/php-fpm7.4 -O Up 9000/tcp
sss-webserver nginx -g daemon off; Up 0.0.0.0:8080->80/tcp,:::8080->80/tcp
While in reality, the containers for this project are named "mx" as you can see here:
version: "3.1"
services:
db:
image: mysql:8.0
container_name: sss-mx-mysql
environment:
MYSQL_DATABASE: ${SSS_DB_NAME:-sss}
MYSQL_ROOT_PASSWORD: ${SSS_DB_RPASSWORD:-sss}
MYSQL_PASSWORD: ${SSS_DB_PASSWORD:-sss}
MYSQL_USER: ${SSS_DB_USERNAME:-sss_user}
volumes:
- ./mysql-volume:/var/lib/mysql
ports:
- "8091:3306"
webserver:
image: nginx:alpine
container_name: sss-mx-webserver
working_dir: /application
volumes:
- ../../:/application
- ./docker/nginx/nginx.conf:/etc/nginx/conf.d/default.conf
ports:
- "8090:80"
php-fpm:
env_file:
- ./docker/php-fpm/.env
environment:
PHP_IDE_CONFIG: "serverName=${SERVER_NAME:-SssWeb}"
build:
args:
user: sss-user
uid: 1000
context: ./docker/php-fpm
container_name: sss-mx-php-fpm
working_dir: /application
volumes:
- ../../:/application
- ./docker/php-fpm/php-ini-overrides.ini:/etc/php/7.4/fpm/conf.d/99-overrides.ini
- ./docker/php-fpm/xdebug.ini:/etc/php/7.4/cli/conf.d/20-xdebug.ini
Why docker-compose gets confused and shows me data from another project?
Related
I can't run MYSQL first in docker compose
services:
mysql:
image: mysql:latest
command: --default-authentication-plugin=mysql_native_password
restart: unless-stopped
volumes:
- mydb:/var/lib/mysql
- ./init:/docker-entrypoint-initdb.d
environment:
MYSQL_DATABASE: db
# Password for root access
MYSQL_ROOT_PASSWORD: root
ports:
# <Port exposed> : < MySQL Port running inside container>
- 3307:3306
volumes:
mydb:
sms-service:
image: sms-service:latest
container_name: SMS-service
network_mode: bridge
restart: unless-stopped
build:
context: /home/iv/Desktop/service-SMS
dockerfile: dockerfile
volumes:
- /home/iv/Desktop:/usr/src/app/dir
- /var/run/dbus:/var/run/dbus
I've created docker-compose.yml file with the following content. My docker service runs ok, docker run hello-world works just fine and after running command
docker-compose build && docker-compose up -d
I see no errors but in the browser I'm getting an error Unable to connect when I go to localhost:8000
version: '3'
services:
nginx:
image: nginx:stable-alpine
container_name: nginx
volumes:
- ./src:/var/www/html
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
ports:
- "8000:80"
depends_on:
- php
- mysql
php:
build:
context: .
dockerfile: Dockerfile
container_name: php
volumes:
- ./src:/var/www/html
ports:
- "9000:9000"
mysql:
image: mysql:8.0
container_name: mysql
restart: unless-stopped
ports:
- "3306:3306"
volumes:
- ./mysql:/var/lib/mysql
environment:
MYSQL_DATABASE: db
MYSQL_USER: user
MYSQL_PASSWORD: password
MYSQL_ROOT_PASSWORD: root
SERVICE_NAME: mysql
When I run command
docker-compose exec php ls
I can see the list of files and folders
i have serveral services in my docker-compose file, it looks like this:
version: '3.7'
services:
web:
build: ./
command: gunicorn --bind 0.0.0.0:5000 --workers 2 --worker-connections 5000 --timeout 6000 manage:app
volumes:
- ./:/usr/src/app/
- static_volume:/usr/src/app/static_files
expose:
- 5000
env_file:
- ./.env.prod
depends_on:
- mongodb
mongodb:
image: mongo:4.4.1
restart: unless-stopped
command: mongod
ports:
- '27017:27017'
environment:
MONGODB_DATA_DIR: /data/db
MONDODB_LOG_DIR: /dev/null
MONGO_INITDB_ROOT_USERNAME:
MONGO_INITDB_ROOT_PASSWORD:
volumes:
- mongodbdata:/data/db
nginx:
build: ./nginx
volumes:
- static_volume:/usr/src/app/static_files
ports:
- 5001:8000
depends_on:
- web
volumes:
mongodbdata:
static_volume:
and i have public repository on my docker hub account, i want to push all images in my app to that repo, anyone can help?
You should add image names to your services, including your docker hub id, e.g.:
services:
web:
build: ./
image: docker-hub-id/web:latest
...
Now, you can just call docker-compose push.
See docker-compose push
I have the following docker-compose.yml:
version: '3'
services:
web:
build:
context: .
dockerfile: ./.docker/node.dockerfile
volumes:
- D:\Proj\Web:/app
ports:
- '3000:3000'
depends_on:
- 'db'
networks:
- holder-network
restart: on-failure
tty: true
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
networks:
- holder-network
restart: always
environment:
MYSQL_ROOT_PASSWORD: P#ssw0rd
MYSQL_DATABASE: holder_db
MYSQL_USER: holder_usr
MYSQL_PASSWORD: P#ssw0rd
networks:
holder-network:
driver: bridge
volumes:
db_data:
And the node.dockerfile:
FROM node:7.10
MAINTAINER Juliano Nunes
RUN mkdir /var/www
RUN npm install nodemon -g
WORKDIR /var/www
ADD . /var/www
RUN npm install
CMD nodemon
I'm changing the files under D:\Proj\Web from the host, however it doesn't update the files in the container. Why?
I've found the error. My docker-compose.yml was using /app as the path and node.dockerfile was using /var/www.
Here's the updated (working) version:
version: '3'
services:
web:
build:
context: .
dockerfile: ./.docker/node.dockerfile
volumes:
- D:\Proj\Web:/var/www
ports:
- '3000:3000'
depends_on:
- 'db'
networks:
- holder-network
restart: on-failure
tty: true
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
networks:
- holder-network
restart: always
environment:
MYSQL_ROOT_PASSWORD: P#ssw0rd
MYSQL_DATABASE: holder_db
MYSQL_USER: holder_usr
MYSQL_PASSWORD: P#ssw0rd
networks:
holder-network:
driver: bridge
volumes:
db_data:
To map a host volume in a container running on docker for windows, you need to ensure your drive is shared into the embedded VM. Otherwise, the directory will mount from the VM's filesystem which will be empty at that location. You need to go into the docker settings on Windows and add the D drive to the shared directory list. See docker's documentation on this here: https://docs.docker.com/docker-for-windows/#shared-drives
I have two project using docker, in first project is laravel, and second is wordpress. In laravel I want to connect both database (to convert laravel database to wordpress database).
but I don't know how to connect it:
here is two docker-compose.yml file:
in laravel:
version: '2'
services:
# The Application
app:
build:
context: ./
dockerfile: app.dockerfile
working_dir: /var/www
volumes:
- ./:/var/www
environment:
- "DB_PORT=3306"
- "DB_HOST=database"
# The Web Server
web:
build:
context: ./
dockerfile: web.dockerfile
working_dir: /var/www
volumes_from:
- app
ports:
- 8081:80
# The Database
database:
image: mysql:5.6
volumes:
- dbdata:/var/lib/mysql
environment:
- "MYSQL_DATABASE=homestead"
- "MYSQL_USER=homestead"
- "MYSQL_PASSWORD=secret"
- "MYSQL_ROOT_PASSWORD=secret"
ports:
- "33061:3306"
volumes:
dbdata:
and my docker-compose.yml file in wordpress:
version: '2'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: 123456
MYSQL_DATABASE: wpshop
MYSQL_USER: root
MYSQL_PASSWORD: 123456
wordpress:
depends_on:
- db
image: wordpress:latest
volumes:
- ./:/var/www/html
ports:
- "8080:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: root
WORDPRESS_DB_PASSWORD: 123456
volumes:
db_data:
I cd to each project and run docker-compose up -d
Please help me!
Create an external network and use that network as default network for all your containers. This way you'll be able to reach all container by its name.
Take a look to Docker container networking: https://docs.docker.com/engine/userguide/networking/