Update shared volume from data container - apache

Hi guys i'm in this situation, i'd like to deploy the changes in my source code by rebuilding the data container which contains a COPY command for transfer the source in the volume. However when i rebuild the data image and re-run docker-compose i stuck with the old code and the only way to update everything is to remove the webroot volume and recreate it.
Where is the mistake??
server:
build: ./docker/apache
image: server:1.3.16
restart: always
links:
- fpm
ports:
- 80:80 # HTTP
- 443:443 # HTTPS
volumes:
- webroot:/var/www/html:ro
fpm:
build: ./docker/php
image: fpm:1.0
restart: always
links:
- database
volumes:
- webroot:/var/www/html
data:
build:
context: .
dockerfile: dataDockerFile
image: smanapp/data:1.0.0
volumes:
- webroot:/var/www/html
volumes:
webroot:

The named volume webroot is meant to persist data across container restart/rebuilds. The only time the data in the volume is updated from an image is when the volume is created, and the contents of the directory in the image are copied in.
It looks like you mean to use volumes_from which is how you get container to mount volumes defined on data. This is the original "data container" method of sharing data that volumes were designed to replace.
version: "2.1"
services:
server:
image: busybox
volumes_from:
- data
command: ls -l /var/www/html
fpm:
image: busybox
volumes_from:
- data
command: ls -l /var/www/html
data:
build: .
image: dply/data
volumes:
- /var/www/html
Note that this has been replaced in version 3 of the compose file so you may need to stick with recreating the volume if you want to use newer features.

Related

Variable substitution in docker-compose command

I need to pass env variable from file to a command in a docker-compose but it seems impossible.
So I try first with environment var but it doesn't work again. How can I do that?
version: '3'
services:
nginx-service-xxx:
image: service-xxx-nginx:latest
ports:
- 80:80
restart: always
service-xxx:
image: service-xxx:latest
# env_file:
# - db-settings.env
environment:
- PORT=80
- PG-HOST=192.168.0.101
- PG-DATABASE=xxx
- PG-USER=postgres
- PG-PASSWORD=postgres
restart: always
command: python xxx/main.py --port=$$PORT --pg-host=$$PG-HOST --pg-database=$$PG-DATABASE --pg-user=$$PG-USER --pg-password=$$PG-PASSWORD
try to move the complexity of the command to a docker entry point.
First, you need to add the following entry point to your project (make it executable)
#!/bin/bash -e
case $1 in
web)
python xxx/main.py --port=$PORT --pg-host=$PG-HOST --pg-database=$PG-DATABASE --pg-user=$PG-USER --pg-password=$PG-PASSWORD
;;
*)
exec "$#"
;;
esac
exit 0
update the docker file for your service
From base-image
COPY ./docker-entrypoint.sh /
ENTRYPOINT ["/docker-entrypoint.sh"]
update compose
version: '3'
services:
nginx-service-xxx:
image: service-xxx-nginx:latest
ports:
- 80:80
restart: always
service-xxx:
image: service-xxx:latest
environment:
- PORT=80
- PG-HOST=192.168.0.101
- PG-DATABASE=xxx
- PG-USER=postgres
- PG-PASSWORD=postgres
restart: always
command: web

Building your own docker images of SeleniumHQ/docker-selenium

I'm not sure if it is a bug or just me being stupid but here is the case.
I want to build my image based on StandaloneChromeDebug. Following the Wiki:
Pull the repo.
Generate image:
$ make standalone_chrome_debug
Build the Dockerfile to insure that no errors arise:
$ docker build --no-cache etc/docker-selenium/StandaloneChromeDebug/
Set up my image to the docker-compose.yml like:
selenium-hub:
container_name: selenium-hub
build: ./etc/docker-selenium/StandaloneChromeDebug/
volumes:
- /dev/shm:/dev/shm
ports:
- "4444:4444"
- "5900:5900"
environment:
- HUB_HOST=selenium-hub
- HUB_PORT=4444
And... nothing. The container is running (no errros) but Selenium doesn't work, container log is empty, /opt/ folder is empty. What am i doing wrong? How to debug the thing?
Path is wrong, use build: /etc/docker-selenium/StandaloneChromeDebug/ without .
If you try to cd to ./etc/docker-selenium/StandaloneChromeDebug/, you will get an error.
version: "3.5"
services:
selenium-hub:
container_name: selenium-hub
build: /etc/docker-selenium/StandaloneChromeDebug/
volumes:
- /dev/shm:/dev/shm
ports:
- "4444:4444"
- "5900:5900"
environment:
- HUB_HOST=selenium-hub
- HUB_PORT=4444
Exapmle:
I feel you are using "build" tag in your compose file rather than "image". Please use "image" tag instead and see if that runs your image correctly.
Also can you please show how you are launching your docker services and what the output is?
Reference to build command

Slow apache + mysql inside of Docker

I have a problem with performance of my Dockerized app. I have Windows OS. When I run my app using xampp it takes the page ~1 second to load. When I run it inside of Docker it takes ~5 seconds for the page to load. I tried:
1. Docker
2. Docker Toolbox (which creates VirtualBox linux machine and runs Docker inside of it)
Result are the same. Here is my Docker-compose file:
version: '3'
networks:
default:
driver: bridge
services:
webserver:
build: ./docker/webserver
image: yiisoftware/yii2-php:7.3-apache
ports:
- "80:80"
- "443:443"
networks:
- default
volumes:
- /aaa:/var/www/html
links:
- db:mysql
environment:
MYSQL_PORT_3306_TCP_ADDR: db
db:
image: mysql:5.7
ports:
- "3306:3306"
networks:
- default
volumes:
- ./db:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=pass
- MYSQL_DATABASE=aaa
Can anybody give me a hint how to fix this? Or this is a regular behavior on Windows pc? Thank you.
The reason was that there was no APCU inside of the container. And without the cache code was 20 times slowlier. Always check if you need all necessary libs and modules inside of your containers!

How to copy files from docker container to host using docker-compose in docker-machine

I have reports generated in gradle container for my selenium tests, I am trying to copy the files from docker container to local host. As a work around, I have used docker cp to copy files from container to my local and it works. How to achieve it with docker-compose volumes.
Below is my docker-compose.yml
version: "3 "
services:
selenium-hub:
image: selenium/hub
container_name: selenium-hub_compose
ports:
- "4444:4444"
chrome:
image: selenium/node-chrome-debug
container_name: selenium-chrome
depends_on:
- selenium-hub
ports:
- "5900"
environment:
- http_proxy=http://x.x.x.x:83
- https_proxy=http://x.x.x.x:83
- HUB_HOST=selenium-hub
- HUB_PORT=4444
gradle:
image: gradle:jdk8
container_name: selenium-gradle
build:
context: .
dockerfile: dockerfile
I run the command docker-compose up -> it runs the selenium tests and generates the report in the container.
Can anyone help on this?
The normal way to pass data from container to host is using docker volumes.
In short you specify a host directory and map it to the directory inside container. And that directory should be used to save your test reports
services:
selenium-hub:
image: selenium/hub
container_name: selenium-hub_compose
ports:
- "4444:4444"
volumes:
- ./path/to/report/folder:/host/reports
See docker documentation
https://docs.docker.com/compose/compose-file/#/volumes-volumedriver
Similar question:
How do I mount a host directory as a volume in docker compose
Power off the machine in Virtual box -> Change the Advanced settings in Virtual box
Goto Shared Folders in Virtual box
Give Path :: C:\DockerResults : Give a logical name for the Folder name
Restart the machine in DockerTerminal with the below command
docker-machine restart default
After machine is started open the Virtual box
Create a directory in the Virtual machine : sudo mkdir /Results
Mount the directory to the local windows machine by executing the below command in virtual box:
Sudo mount –t vboxsf DockerResults /Results
Add volumes as below in docker-compose file
volumes:
- /DockerResults:/home/Reports/

How can I eliminate invalid volume specification error when using docker-compose to create a named volume for sql db in Windows Container?

I'm trying to use docker-compose to create a named volume for sql db in Windows container.
I keep getting the error:
"Severity Code Description Project File Line Suppression State
Error Building webpresentation
Recreating dockercompose6946136170613312467_webpresentation_1 ...
Creating dockercompose6946136170613312467_db_1 ...
Creating dockercompose6946136170613312467_db_1 ... error
ERROR: for dockercompose6946136170613312467_db_1 Cannot create container for service db: invalid volume specification: 'dockercompose6946136170613312467_sqlvolume:/var/opt/mssql:rw'
Recreating dockercompose6946136170613312467_webpresentation_1 ... done
ERROR: for db Cannot create container for service db: invalid volume specification: 'dockercompose6946136170613312467_sqlvolume:/var/opt/mssql:rw'
Encountered errors while bringing up the project..
For more troubleshooting information, go to http://aka.ms/DockerToolsTroubleshooting docker-compose C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Sdks\Microsoft.Docker.Sdk\build\Microsoft.VisualStudio.Docker.Compose.targets 363 "
Here is my docker-compose file:
version: '3.4'
services:
webpresentation:
image: webpresentation
build:
context: .
dockerfile: WebPresentation\Dockerfile
db:
image: microsoft/mssql-server-windows-express
environment:
ACCEPT_EULA: Y
SA_PASSWORD: Test1
ports:
- "1433:1433"
volumes:
- sqlvolume:/var/opt/mssql
volumes:
sqlvolume:
I should also mention that I've used Visual Studio's Docker tools to set this project up here is the docker-compose.override.yml file as well:
version: '3.4'
services:
webpresentation:
environment:
- ASPNETCORE_ENVIRONMENT=Development
ports:
- "80"
networks:
default:
external:
name: nat
Can anyone point me in the right direction as to how to eliminate this error? Thanks!
If anyone else is having this problem, the project successfully built in Visual Studio after I did a docker volume ls and realized the actual volume name had an auto-generated "dockercompose" prefix. I used a more direct path to the folder on the hard drive in the db's volume definition. I then replaced every instance of "sqlvolume" with the new name. My complete docker-compose file is as follows:
version: '3.4'
services:
webpresentation:
image: webpresentation
build:
context: .
dockerfile: WebPresentation\Dockerfile
db:
image: microsoft/mssql-server-windows-express
environment:
ACCEPT_EULA: Y
SA_PASSWORD: Test1
ports:
- "1433:1433"
volumes:
- "C:\\ProgramData\\Docker\\volumes\\dockercompose6946136170613312467_sqlvolume:c:\\mssql"
volumes:
dockercompose6946136170613312467_sqlvolume: