I am having a funny error when I try to run a docker-compose. I have reinstall the VM several times, everything is update and install but I cannot run a compose.
$ sudo docker-compose up -d
Creating network "apache2_default" with the default driver
Building mysql
ERROR: Error processing tar file(exit status 1): permission denied
My docker-composer.yml file:
version: '2'
services:
mysql:
build: ./mysql
environment:
MYSQL_ROOT_PASSWORD: pass
volumes:
- db:/var/lib/mysql
php:
build: ./php
ports:
- '80:80'
volumes:
- ./html:/var/www/html
depends_on:
- mysql
volumes:
db:
I have run this in Mac and it works
Edit:
Dockerfile fot mysql:
FROM mysql:5.7
COPY ./my.cnf /etc/mysql/conf.d/
The docker build build command can fail with permission error when there are files (or folders) in the build context directory which aren't owned by the current user.
This situation happens when you mount a volume to a host directory ; the files in that directory might be owned by root.
The fix is quite easy: just create a .dockerignore file with the name of the directories/files you don't own and don't require in the docker image build.
For instance:
docker run -d -v $(pwd)/data-volume:/var/lib/mysql mysql
would create a data-volume directory.
If you were to build a Dockerfile, you would have the following content in your .dockerignore:
data-volume
Related
Dockerfile:
FROM hseeberger/scala-sbt:8u222_1.3.5_2.13.1
WORKDIR /code/SimpleStocks
COPY ./SimpleStocks .
RUN sbt dist
WORKDIR /code/SimpleStocks/target/universal
RUN unzip simplestocks-0.0.1.zip
WORKDIR /code/SimpleStocks/target/universal/simplestocks-0.0.1
CMD ["bin/simplestocks"]
docker-compose.yml:
version: "3.7"
services:
app:
container_name: simple-stocks
image: simple-stocks:1.0.0
build: .
ports:
- '9000:9000'
volumes:
- .:/code
links:
- pgdb1
pgdb1:
image: postgres
environment:
POSTGRES_DB: simple_stocks
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
volumes:
- pgdb1data:/var/lib/postgresql/data/
- ./docker_postgres_init.sql:/docker-entrypoint-initdb.d/docker_postgres_init.sql
ports:
- '5432:5432'
volumes:
pgdb1data:
When I manually run simple-stocks container using docker run -it {imageId}, I am able to run it successfully; but, on doing docker compose up I am receiving:
Error response from daemon: OCI runtime create failed:
container_linux.go:380: starting container process caused: exec:
"bin/simplestocks": stat bin/simplestocks: no such file or directory:
unknown
Your Dockerfile is building the application in /code/SimpleStocks/target/universal/simplestocks-0.0.1, but then your Compose file bind-mounts a host directory over /code, which hides everything the Dockerfile does. The bind mount is unnecessary and deleting it will resolve this issue.
Bind-mounting a host directory over your entire built application usually is not a best practice. I most often see it trying to convince Docker to emulate a local development environment, but even that approach doesn't make sense for a compiled language like Scala.
You can safely remove the volumes: block. The obsolete links: can also be removed. You don't need to manually specify container_name:, nor do you need to specify both build: and image: unless you're planning to push the built image to a registry. That would reduce the Compose setup to just:
version: '3.8'
services:
app:
build: .
ports:
- '9000:9000'
pgdb1: (as in the question originally)
volumes:
pgdb1data:
I'm running a Docker deployment for an application. I'm mounting a volume where I want the external path to be provided by a shell environment variable. I get this error:
ERROR: for video-server Cannot create container for service video-server: invalid volume specification: '46b9d2fb3b9b13c9404d31bae571dac3f633122393c4a77f2561afb8aed5c06e:=/opt/videos:rw': invalid mount config for type "volume": invalid mount path: '=/opt/videos' mount path must be absolute
My docker-compose configuration is this:
video-server:
build:
context: .
dockerfile: video-server_Dockerfile
container_name: video-server
networks:
- videoManagerNetwork
environment:
- VIDEO_MANAGER_DIR=/opt/videos
volumes:
- ${VIDEO_MANAGER_DIR_PROD}=/opt/videos
ports:
- 9000:8080
I can see the correct value of the VIDEO_MANAGER_DIR_PROD environment variable by doing both of these commands, so I know it's on my shell:
echo $VIDEO_MANAGER_DIR_PROD
sudo echo $VIDEO_MANAGER_DIR_PROD
What's strange is that, if I do a complete wipe of my docker configurations (sudo docker system prune --all --volumes), and then run the docker-compose for the first time (sudo docker-compose up -d), everything works.
However, if I take the container down, rebuild it, and try to run that same command (sudo docker-compose up -d) again, then I get the error displayed above.
You cannot assign the source volume like a variable, so you will use : for this assignment.
Documentation about Docker Compose volumes: docs.docker.com
video-server:
build:
context: .
dockerfile: video-server_Dockerfile
container_name: video-server
networks:
- videoManagerNetwork
environment:
- VIDEO_MANAGER_DIR: /opt/videos
volumes:
- ${VIDEO_MANAGER_DIR_PROD}:/opt/videos
ports:
- 9000:8080
I have 2 docker containers. One running tomcat and the other running mysql. I want to copy a .sql file into the already existing "docker-entrypoint-initdb.d" folder of the mysql container.
I used the following command in my Dockerfile:
COPY test.sql /docker-entrypoint-initdb.d
After both containers are started I saw that the folder "docker-entrypoint-initdb.d" was created in my tomcat container and the test.sql was copied into it.
The file isn't copied where I need it to be. test.sql wasnt copied into the mysql container.
What can I do?
docker-compose.xml:
version: "2"
services:
db:
image: mysql
environment:
- MYSQL_ALLOW_EMPTY_PASSWORD="true"
myapp:
build: ./myapp
ports:
- 8080:8080
- 3306:3306
Build your own image for the database container with a Dockerfile like this:
FROM mysql
COPY test.sql /docker-entrypoint-initdb.d
tomcat container is build via docker file, where as mysql container(db) is build via the docker image name "mysql".
You can mount the volume with current folder (host) to "/docker-entrypoint-initdb.d" inside the container.
new docker-compose.yml will look like this.
version: "2"
services:
db:
image: mysql
environment:
- MYSQL_ALLOW_EMPTY_PASSWORD="true"
volumes:
- .:/docker-entrypoint-initdb.d
myapp:
build: ./myapp
ports:
- 8080:8080
- 3306:3306
You are building tomcat container, But using Mysql image there, Thats why the file copied to tomcat container.
When containers are up you can docker cp the file manually to the desired location.
If you want to have the database available to container at startup, I suggest you use a dummy container with mounted local filesystem. Then restore the database manually in that container. Then remove the container and modify dockerfile like this:
version: "2"
services:
db:
image: mysql
environment:
- MYSQL_ALLOW_EMPTY_PASSWORD="true"
volumes:
- /my/own/datadir:/var/lib/mysql
myapp:
build: ./myapp
ports:
- 8080:8080
- 3306:3306
Another way would be creating your own image using following dockerfile:
FROM mysql
COPY test.sql /docker-entrypoint-initdb.d
I'm trying to launch a series of Docker Containers using Docker Compose. The problem is I keep getting an error message saying a directory is not valid. I have no idea what directory of mine dos not exist.
Here is my docker-compose.yaml (in the myProj folder):
version: '2'
services:
postgres:
build: ./postgres
environment:
- POSTGRES_PASSWORD=mysecretpassword
frontend:
build: ./frontend
ports:
- "4567:4567"
depends_on:
- postgres
backend:
build: ./backend
ports:
- "5000:5000"
depends_on:
- postgres
And a docker file for my backend container in (myProj/backend):
FROM openjdk:8-alpine
ADD ./backend-0.0.1-SNAPSHOT.jar /usr/src/myproj/
WORKDIR /usr/src/myproj/
CMD java -jar backend-0.0.1-SNAPSHOT.jar
When I run "docker-compose up" I get the following message:
docker_postgres_1 is up-to-date
Starting docker_backend_1
Starting docker_frontend_1
ERROR: for frontend Cannot start service frontend: oci runtime error: not a directory
ERROR: for backend Cannot start service backend: oci runtime error: not a directory
ERROR: Encountered errors while bringing up the project.
It seems the Postgres container builds fine. What directory do I need to fix?
Edit:
Folder Structure
myProj
- postgres
- Dockerfile
- frontend
- Dockerfile
- frontend-0.0.1-SNAPSHOT.jar
- backend
- Dockerfile
- backend-0.0.1-SNAPSHOT.jar
Try restarting your Docker service first.
If that does not work, add this after the FROM statement in the Dockerfile:
RUN mkdir -p /usr/src/myproj/
I've (kind of) solved my own problem. I since decided to instantiate a CoreOS VM using Vagrant. Once I use CoreOS to run Docker-Compose everything started working as normal. Turns out the problem was not in my implementation, but It must be a bug with Docker-Compose, Docker-Machine, or Docker.
The versions that gave me problems are:
docker-compose version 1.8.0, build d988a55
docker-machine version 0.8.0, build b85aac1
docker version 1.12.0, build 8eab29e
While running on Windows 10 with VirtualBox.
I'm in Fedora 23 and i'm using docker-compose to build two containers: app and db.
I want to use that docker as my dev env, but have to execute docker-compose build and up every time i change the code isn't nice. So i was searching and tried the "volumes" option but my code doesn't get copied to docker.
When i run docker-build, a "RUN ls" command doesn't list the "app" folder or any files of it.
Obs.: in the root folder I have: docker-compose.yml, .gitignore, app (folder), db (folder)
ObsĀ¹.: If I remove the volumes and working_dir options and instead I use a "COPY . /app" command inside the app/Dockerfile it works and my app is running, but I want it to sync my code.
Anyone know how to make it work?
My docker-compose file is:
version: '2'
services:
app:
build: ./app
ports:
- "3000:3000"
depends_on:
- db
environment:
- DATABASE_HOST=db
- DATABASE_USER=myuser
- DATABASE_PASSWORD=mypass
- DATABASE_NAME=dbusuarios
- PORT=3000
volumes:
- ./app:/app
working_dir: /app
db:
build: ./db
environment:
- MYSQL_ROOT_PASSWORD=123
- MYSQL_DATABASE=dbusuarios
- MYSQL_USER=myuser
- MYSQL_PASSWORD=mypass
Here you can see my app container Dockerfile:
https://gist.github.com/jradesenv/d3b5c09f2fcf3a41f392d665e4ca0fb9
Heres the output of the RUN ls command inside Dockerfile:
bin
boot
dev
etc
home
lib
lib64
media
mnt
opt
proc
root
run
sbin
srv
sys
tmp
usr
var
A volume is mounted in a container. The Dockerfile is used to create the image, and that image is used to make the container. What that means is a RUN ls inside your Dockerfile will show the filesystem before the volume is mounted. If you need these files to be part of the image for your build to complete, they shouldn't be in the volume and you'll need to copy them with the COPY command as you've described. If you simply want evidence that these files are mounted inside your running container, run a
docker exec $container_name ls -l /
Where $container_name will be something like ${folder_name}_app_1, which you'll see in a docker ps.
Two things, have you tried version: '3' version two seems to be outdated. Also try putting the working_dir into the Dockerfile rather than the docker-compose. Maybe it's not supported in version 2?
This is a recent docker-compose I have used with volumes and workdirs in the respective Dockerfiles:
version: '3'
services:
frontend:
build:
context: ./frontend
dockerfile: Dockerfile.dev
ports:
- 3001:3001
volumes:
- ./frontend:/app
networks:
- frontend
backend:
build: .
ports:
- 3000:3000
volumes:
- .:/app
networks:
- frontend
- backend
depends_on:
- "mongo"
mongo:
image: mongo
volumes:
- ./data/db:/data/db
ports:
- 27017:27017
networks:
- backend
networks:
frontend:
backend:
You can extend or override docker compose configuration. Please follow for more info: https://docs.docker.com/compose/extends/
I had this same issue in Windows!
volumes:
- ./src/:/var/www/html
In windows ./src/ this syntax might not work in regular command prompt, so use powershell instead and then run docker-compose up -d.
it should work if it's a mounting issue.