I try with no success to access to Mercure's hub through my browser at this URL :
http://locahost:3000 => ERR_CONNECTION_REFUSED
I use Docker for my development. Here's my docker-compose.yml :
# docker/docker-compose.yml
version: '3'
services:
database:
container_name: test_db
build:
context: ./database
environment:
- MYSQL_DATABASE=${DATABASE_NAME}
- MYSQL_USER=${DATABASE_USER}
- MYSQL_PASSWORD=${DATABASE_PASSWORD}
- MYSQL_ROOT_PASSWORD=${DATABASE_ROOT_PASSWORD}
ports:
- "3309:3306"
volumes:
- ./database/init.sql:/docker-entrypoint-initdb.d/init.sql
- ./database/data:/var/lib/mysql
php-fpm:
container_name: test_php
build:
context: ./php-fpm
depends_on:
- database
environment:
- APP_ENV=${APP_ENV}
- APP_SECRET=${APP_SECRET}
- DATABASE_URL=mysql://${DATABASE_USER}:${DATABASE_PASSWORD}#database:3306/${DATABASE_NAME}?serverVersion=5.7
volumes:
- ./src:/var/www
nginx:
container_name: test_nginx
build:
context: ./nginx
volumes:
- ./src:/var/www
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
- ./nginx/sites/:/etc/nginx/sites-available
- ./nginx/conf.d/:/etc/nginx/conf.d
- ./logs:/var/log
depends_on:
- php-fpm
ports:
- "8095:80"
caddy:
container_name: test_mercure
image: dunglas/mercure
restart: unless-stopped
environment:
MERCURE_PUBLISHER_JWT_KEY: '!ChangeMe!'
MERCURE_SUBSCRIBER_JWT_KEY: '!ChangeMe!'
PUBLISH_URL: '${MERCURE_PUBLISH_URL}'
JWT_KEY: '${MERCURE_JWT_KEY}'
ALLOW_ANONYMOUS: '${MERCURE_ALLOW_ANONYMOUS}'
CORS_ALLOWED_ORIGINS: '${MERCURE_CORS_ALLOWED_ORIGINS}'
PUBLISH_ALLOWED_ORIGINS: '${MERCURE_PUBLISH_ALLOWED_ORIGINS}'
ports:
- "3000:80"
I have executed successfully :
docker-compose up -d
docker ps -a :
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0e4a72fe75b2 dunglas/mercure "caddy run --config …" 2 hours ago Up 2 hours 443/tcp, 2019/tcp, 0.0.0.0:3000->80/tcp, :::3000->80/tcp test_mercure
724fe920ebef nginx "/docker-entrypoint.…" 3 hours ago Up 3 hours 0.0.0.0:8095->80/tcp, :::8095->80/tcp test_nginx
9e63fddf50ef php-fpm "docker-php-entrypoi…" 3 hours ago Up 3 hours 9000/tcp test_php
e7989b26084e database "docker-entrypoint.s…" 3 hours ago Up 3 hours 0.0.0.0:3309->3306/tcp, :::3309->3306/tcp test_db
I can reach http://localhost:8095 to access to my Symfony app but I don't know on which URL I am supposed to reach my Mercure's hub.
Thank's for your help !
I tried for months to get symfony + nginx + mysql + phpmyadmin + mercure + docker to work both locally for development and in production (obviously). To no avail.
And, while this isn't directly answering your question. The only way I can contribute is with an "answer", as I don't have enough reputation to only comment, or I would have done that.
If you're not tied to nginx for any reason besides a means of a web server, and can replace it with caddy, I have a repo that is symfony + caddy + mysql + phpmyadmin + mercure + docker that works with SSL both locally and in production.
https://github.com/thund3rb1rd78/symfony-mercure-website-skeleton-dockerized
Related
I'm using docker with docker-compose.yml file.
There I put two different services inside, which I'd like to update.
Moreover I ran portainer and added also some other services there:
pi#raspberrypi:~/docker $ docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ec830e789d38 nodered/node-red:latest "npm --no-update-not…" 8 days ago Up 6 minutes (healthy) 0.0.0.0:1880->1880/tcp, :::1880->1880/tcp docker_node-red_1
15aa942b2b94 openhab/openhab:3.1.1 "/entrypoint gosu op…" 8 days ago Up 8 days (healthy) docker_openhab_1
e805e3f527c4 portainer/portainer-ce "/portainer" 8 days ago Up 8 days 0.0.0.0:8000->8000/tcp, :::8000->8000/tcp, 0.0.0.0:9000->9000/tcp, :::9000->9000/tcp, 0.0.0.0:9443->9443/tcp, :::9443->9443/tcp portainer
80990d1ad7e7 influxdb:latest "/entrypoint.sh infl…" 9 months ago Up 8 days InfluxDB
My actual docker-compose.yml file looks like this:
pi#raspberrypi:~/docker $ cat docker-compose.yml
version: "2"
services:
openhab:
image: "openhab/openhab:3.1.1"
restart: always
network_mode: host
volumes:
- "/etc/localtime:/etc/localtime:ro"
- "/etc/timezone:/etc/timezone:ro"
- "./openhab_addons:/openhab/addons"
- "./openhab_conf:/openhab/conf"
- "./openhab_userdata:/openhab/userdata"
environment:
USER_ID: "1000"
GROUP_ID: "1000"
OPENHAB_HTTP_PORT: "8080"
OPENHAB_HTTPS_PORT: "8443"
EXTRA_JAVA_OPTS: "-Duser.timezone=Europe/Berlin"
services:
node-red:
image: nodered/node-red:latest
environment:
- TZ=Europe/Amsterdam
ports:
- "1880:1880"
networks:
- node-red-net
volumes:
- node-red-data:/data
devices:
- "/dev/ttyUSB0:/dev/ttyUSB0"
volumes:
node-red-data:
networks:
node-red-net:
In order to update the openhab container from 3.1.1 to 3.2.0, I changed the image name inside compose file to openhab/openhab:3.2.0.
Afterwards I started docker-compose pull and the system only checked if there is a new image for node-red available. But not for openhab.
What is wrong?
You need to put all the services under a single services key. That's also why it's plural.
services:
openhab:
...
node-red:
...
I have a docker-compose file that I use the image block in the service to name. For example
version: '3'
services:
redis:
image: redis
restart: unless-stopped
ports:
- "6379"
worker:
image: worker:production
build: .
user: root
command: celery -A ExactEstate worker --loglevel=info
env_file: ./.env.prod
restart: unless-stopped
links:
- redis
depends_on:
- redis
beats:
image: beats:production
build: .
user: root
command: celery --pidfile= -A ExactEstate beat -l info --scheduler django_celery_beat.schedulers:DatabaseScheduler
env_file: ./.env.prod
restart: unless-stopped
links:
- redis
depends_on:
- redis
web:
image: web:production
build: .
user: root
command: daphne -b 0.0.0.0 -p 8000 ExactEstate.asgi:application
ports:
- "8000:8000"
env_file: ./.env.prod
restart: unless-stopped
links:
- redis
- worker
- beats
depends_on:
- redis
- worker
- beats
This gives a docker ps of:
0ad78269a9ce beats:production "celery --pidfile= -…" 7 minutes ago Up 7 minutes exactestate_beats_1
1a44f7c98b50 worker:production "celery -A ExactEsta…" 7 minutes ago Up 7 minutes exactestate_worker_1
f3a09723ba66 redis "docker-entrypoint.s…" 7 minutes ago Up 7 minutes 0.0.0.0:32769->6379/tcp exactestate_redis_1
Let's suppose I also have built containers from a different compose file (i.e. staging) How can I use docker-compose to on pull up the exact service/image I want?
For example: docker-compose up web:production or docker-compose up web:staging
You can achieve this by using environment variables. Variables for docker-compose up could be passed as .env file or set by export (or set on Windows) command (docker documentation).
web:
image: web:production
Should be changed to
web:
image: web:${ENV}
And then you can run your application by running
$ export ENV=production && docker-compose up
Or you can create .env file containing line ENV=production. Then you can simply run application with docker-compose up.
I am getting an "Internal Server Error" when trying to install Odoo 12 Community Edition on an AWS EC2 instance using a docker-compose file. My EC2 instance uses Ubuntu 18.04.1 LTS (GNU/Linux 4.15.0-1031-aws x86_64) operating system, Docker version 18.09.0 and docker-compose version 1.23.2.
Here is my docker-compose.yml file:
version: '2'
services:
web:
image: odoo:12.0
depends_on:
- db
ports:
- "8069:8069"
volumes:
- odoo-web-data:/var/lib/odoo
- ./config:/etc/odoo
- ./addons:/mnt/extra-addons
db:
image: postgres:10
environment:
- POSTGRES_PASSWORD=odoo
- POSTGRES_USER=odoo
- PGDATA=/var/lib/postgresql/data/pgdata
volumes:
- odoo-db-data:/var/lib/postgresql/data/pgdata
volumes:
odoo-web-data:
odoo-db-data:
I can see the containers being created as is evidenced by the following output of the "docker ps -a" command:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
64e271db9565 odoo:12.0 "/entrypoint.sh odoo" 2 hours ago Up 2 hours 0.0.0.0:8069->8069/tcp, 8071/tcp ubuntu_web_1
10b3198e3230 postgres:10 "docker-entrypoint.s…" 2 hours ago Up 2 hours 5432/tcp ubuntu_db_1
Moreover, the "docker-compose config" command returned the following output:
services:
db:
environment:
PGDATA: /var/lib/postgresql/data/pgdata
POSTGRES_PASSWORD: odoo
POSTGRES_USER: odoo
image: postgres:10
volumes:
- odoo-db-data:/var/lib/postgresql/data/pgdata:rw
web:
depends_on:
- db
image: odoo:12.0
ports:
- 8069:8069/tcp
volumes:
- odoo-web-data:/var/lib/odoo:rw
- /home/ubuntu/config:/etc/odoo:rw
- /home/ubuntu/addons:/mnt/extra-addons:rw
version: '2.0'
volumes:
odoo-db-data: {}
odoo-web-data: {}
What am I missing here?
I'm trying to create 3 mattermost services on 1 AWS EC2 machine.
Let me explain further with more texts:
When I run docker-compose up -d, I get a service whose structure is like this:
How can I modify the docker related scripts so that I can create 3 sets of service?
I've tried docker-compose up --scale app=3 --scale web=3 --scale db=3. But I can't find any way to specify different port for each of the App container.
The only solution I've found is:
Create 3 copies of mattermost-docker folder.
Change the App port and database connection information.
Run docker-compose up -d 3 times in mattermost-docker1, mattermost-docker2, and mattermost-docker3 separately.
But this solution creates a lot of duplicated files. I don't like it.
Anyone knows how to create 3 sets of mattermost services?
You need to specify a port range in docker compose:
For example, for 10 container scalling:
version: '3'
services:
web:
...
ports:
- "80-90:443"
app:
...
ports:
- "8000-8010"
Note that you don't need to change port inside container (443, 444, 445). You can use the same, and furthermore that's recommended, because although you use different containers in a port range, is easier if they use the same nginx configuration.
This starts sets of services using 3 separate databases (nginx and mongo used as example).
version: '3'
services:
web1:
container_name: web1
image: nginx:latest
ports:
- 8080:8080
app1:
container_name: app1
image: nginx:latest
ports:
- "8081:8081"
db1:
container_name: db1
image: mongo
ports:
- 27017
web2:
container_name: web2
image: nginx:latest
ports:
- 8082:8082
app2:
container_name: app2
image: nginx:latest
ports:
- "8083:8083"
db2:
container_name: db2
image: mongo
ports:
- 27018
web3:
container_name: web3
image: nginx:latest
ports:
- 8084:8084
app3:
container_name: app3
image: nginx:latest
ports:
- "8085:8085"
db3:
container_name: db3
image: mongo
ports:
- 27019
Local Test:
NAMES STATUS PORTS IMAGE
db2 Up About a minute 27017/tcp, 0.0.0.0:32803->27018/tcp mongo
web1 Up About a minute 80/tcp, 0.0.0.0:32802->8080/tcp nginx:latest
db1 Up About a minute 0.0.0.0:32801->27017/tcp mongo
app1 Up About a minute 80/tcp, 0.0.0.0:32800->8081/tcp nginx:latest
app3 Up About a minute 80/tcp, 0.0.0.0:32798->8085/tcp nginx:latest
db3 Up About a minute 27017/tcp, 0.0.0.0:32799->27019/tcp mongo
app2 Up About a minute 80/tcp, 0.0.0.0:32797->8083/tcp nginx:latest
web3 Up About a minute 80/tcp, 0.0.0.0:32796->8084/tcp nginx:latest
web2 Up About a minute 80/tcp, 0.0.0.0:32795->8082/tcp nginx:latest
I'm new to Docker and I'm trying to find out how to set the name of the created data volume. Currently the directory is automatically named as a long hash under /var/libs/docker which is far from user friendly.
I'm attempting to set up a development environment for MODX as shown here:
https://github.com/modxcms/docker-modx
Currently my docker-compose.yml file is as follows:
web:
image: modx
links:
- db:mysql
ports:
- 80:80
db:
image: mysql
environment:
MYSQL_ROOT_PASSWORD: example
ports:
- 3306:3306
command: mysqld --sql-mode=NO_ENGINE_SUBSTITUTION
myadmin:
image: phpmyadmin/phpmyadmin
links:
- db:db
ports:
- 8080:8080
This works perfectly but I'm unsure as to how to name the data volume that I would edit directly with my IDE.
(As a side question, does it have to be created under /var/libs/docker ? Or is there a way of setting it to a directory in my home folder?)
Update:
Thanks to the help from #juliano I've updated my docker-compose.yml file to:
version: '2'
services:
web:
image: modx
volumes:
- html:/home/muzzstick/dev/modxdev
links:
- db:mysql
ports:
- 80:80
db:
image: mysql
environment:
MYSQL_ROOT_PASSWORD: example
ports:
- 3306:3306
command: mysqld --sql-mode=NO_ENGINE_SUBSTITUTION
myadmin:
image: phpmyadmin/phpmyadmin
links:
- db:db
ports:
- 8080:8080
volumes:
html:
external: false
Unfortunately this seems to stop the web container from running.
db and myadmin containers show they're running ok.
There weren't any errors... if I type docker start docker_web_1 it appears to start but docker ps -a shows it exited as soon as it started.
Update 2
Running docker-compose up -d appears to run without issue. But then as you can see below, the web container exits as soon as it's created.
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a1dd6d8ac94e modx "/entrypoint.sh apach" 10 seconds ago Exited (1) 5 seconds ago docker_web_1
ee812ae858dc phpmyadmin/phpmyadmin "/run.sh phpmyadmin" 10 seconds ago Up 5 seconds 80/tcp, 0.0.0.0:8080->8080/tcp docker_myadmin_1
db496134e0cf mysql "docker-entrypoint.sh" 11 seconds ago Up 10 seconds 0.0.0.0:3306->3306/tcp docker_db_1
Update 3
OK the error logs for this container shows:
error: missing MODX_DB_HOST and MYSQL_PORT_3306_TCP environment variables
Did you forget to --link some_mysql_container:mysql or set an external db
with -e MODX_DB_HOST=hostname:port?
This error appears to be originating from https://github.com/modxcms/docker-modx/blob/master/apache/docker-entrypoint.sh#L15-L20
Could it be something like linking is handled differently in docker-compose version 2?
To create a named data volume using the version 2 of compose files you will have a separated area:
version: '2'
services:
db:
image: postgres
volumes:
- amazingvolume:/var/lib/postgresql/data
volumes:
amazingvolume:
external: true
So you can define the volume name (amazingvolume), if it's external or not and under your service (db in this example) you can define which directory you gonna mount.
Just search in the docker documentation for hosted mounted volumes:
version: '2'
services:
web:
image: modx
environment:
- MYSQL_PORT_3306_TCP=3306
- MODX_DB_HOST=mysql:3306
volumes:
- /home/muzzstick/dev/modxdev/html:/var/www/html
links:
- db:mysql
ports:
- 80:80
db:
image: mysql
environment:
MYSQL_ROOT_PASSWORD: example
ports:
- 3306:3306
command: mysqld --sql-mode=NO_ENGINE_SUBSTITUTION
myadmin:
image: phpmyadmin/phpmyadmin
links:
- db:db
ports:
- 8080:8080
Change /var/www/html to the directory where the html files will be inside the container. And also create the directory at the left in your host and give read permission to all users.
Regards