Let's say I have a couple of services web1 and web2 and I can spin them up in prod or dev
docker-compose -f docker-compose.yml -f docker-compose.dev.yml up -d
docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d
Now let's say I do the same for a testing config. If my test yml were only changing the container name, for example,
version: '3.6'
services:
web1:
container_name: web1_test
web2:
container_name: web2_test
and I had my web services already running, then this would recreate the services, effectively replacing their containers with new ones bearing the new config (in this case a new name). But I'd rather not, it'd be nice to just spin them up and down without interfering with the originals.
A better experience would be
version: '3.6'
services:
web1:
service_name: web1_test
web2:
service_name: web2_test
then I could start the test versions and stop them without touching the originals.
docker-compose -f docker-compose.yml -f docker-compose.test.yml up -d web1_test web2_test
Is there any way to leave the original services up and spin up some new test instances with a simple config overlay?
Note: I'm currently using docker-compose run to meet my needs. In practice I'm also modifying env variables and ports likes so:
docker-compose -f Docker/docker-compose.yml -f Docker/docker-compose.dev.yml run -d --name web1_test -e VAR1=web1_test_var -p 5001:5000 web1
so I already know 'how to get it done', I'm looking more for, am I missing a better way to accomplish the same? It'd be nice to have the port and env and name stuff in a config wouldn't it?
Instead of using container_name per service you could use different project names for the same docker-compose.yml using the flag: -p, --project-name NAME.
docker-compose -f docker-compose.yml -p foo up -d
foo_web_1
foo_web_2
docker-compose -f docker-compose.yml -p bar up -d
bar_web_1
bar_web_2
I am trying to run bamboo on server using docker containers. When i running on local machine work normally and volume save datas successfully. But when i run same docker compose file on server, volume data not save my datas.
docker-compose.yml
version: '3.2'
services:
bamboo:
container_name: bamboo-server_test
image: atlassian/bamboo-server
volumes:
- ./volumes/bamboo_test_vol:/var/atlassian/application-data/bamboo
ports:
- 8085:8085
volumes:
bamboo_test_vol:
Run this compose file on local machine
$ docker-compose up -d
Creating network "test_default" with the default driver
Creating volume "test_bamboo_test_vol" with default driver
Creating bamboo-server_test ... done
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
916c98ca1a9d atlassian/bamboo-server "/entrypoint.sh" 24 minutes ago Up 24 minutes 0.0.0.0:8085->8085/tcp, 54663/tcp bamboo-server_test
$ ls
docker-compose.yml volumes
$ cd volumes/bamboo_test_vol/
$ ls
bamboo.cfg.xml logs
localhost:8085
Run this compose file on server
$ ssh <name>#<ip_address>
password for <name>:
$ docker-compose up -d
Creating network "test_default" with the default driver
Creating volume "test_bamboo_test_vol" with default driver
Creating bamboo-server_test ... done
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
38b77e1b736f atlassian/bamboo-server "/entrypoint.sh" 12 seconds ago Up 11 seconds 0.0.0.0:8085->8085/tcp, 54663/tcp bamboo-server_test
$ ls
docker-compose.yml volumes
$ cd volumes/
$ cd bamboo_test_vol/
$ ls
$ # VOLUME PATH IS EMPTY
server_ip:8085
I didn't have this problem when I tried the same process for jira-software. Why can't it work through the bamboo server even though I use the exact same compose file?
I had the same problem when I wanted to upgrade my Bamboo server instance with my mounted host volume for the bamboo-home directory.
The following was in my docker-compose file:
version: '2.2'
bamboo-server:
image: atlassian/bamboo-server:${BAMBOO_VERSION}
container_name: bamboo-server
environment:
TZ: 'Europe/Berlin'
restart: always
init: true
volumes:
- ./bamboo/bamboo-server/data:/var/atlassian/application-data/bamboo
ports:
- "8085:8085"
- "54663:54663"
When i started with docker-compose up -d bamboo-server, the container never took the files from the host system. So I tried it first without docker-compose, following the instructions of Atlassian Bamboo with the following command:
docker run -v ./bamboo/bamboo-server/data:/var/atlassian/application-data/bamboo --name="bamboo-server" --init -d -p 54663:54663 -p 8085:8085 atlassian/bamboo-server:${BAMBOO_VERSION}
The following error message was displayed:
docker: Error response from daemon: create ./bamboo/bamboo-server/data: "./bamboo/bamboo-server/data" includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed. If you intended to pass a host directory, use absolute path.
So I converted the error message and took the absolute path:
docker run -v /var/project/bamboo/bamboo-server/data:/var/atlassian/application-data/bamboo --name="bamboo-server" --init -d -p 54663:54663 -p 8085:8085 atlassian/bamboo-server:${BAMBOO_VERSION}
After the successful start, I switched to the docker container via SSH and all files were as usual in the docker directory.
I transferred the whole thing to the docker-compose file and took the absolute path in the volumes section. Subsequently it also worked with the docker-compose file.
My docker-compose file then looked like this:
[...]
init: true
volumes:
- /var/project/bamboo/bamboo-server/data:/var/atlassian/application-data/bamboo
ports:
[...]
Setting up a containerized Bamboo Server is not supported for these reasons;
Repository-stored Specs (RSS) are no longer processed in Docker by default. Running RSS in Docker was not possible because;
there is no Docker capability added on the Bamboo server by default,
the setup would require running Docker in Docker.
When calling docker-compose in different directories, I get conflict errors and problems with networking:
Problem with conflicts
docker-compose.yml
version: '3'
services:
redis:
image: "redis:alpine"
container_name: redis
I. create and start docker container by docker-compose => OK
$ docker-compose up --force-recreate -d
Creating redis ... done
II. recreate and start docker container by docker-compose => OK
$ docker-compose up --force-recreate -d
Recreating redis ... done
III. copy docker-compose.yml to other directory.
Then try to recreate from other directory => ERROR
$ cp docker-compose.yml red2/
$ cd red2/
$ docker-compose up --force-recreate -d
Creating redis ... error
ERROR: for redis Cannot create container for service redis: Conflict. The container name "/redis" is already in use by container "1ba060b545f716731ac1c5992b680e4d4b3639fc0ffeb291899c712f0839d23a". You have to remove (or rename) that container to be able to reuse that name.
ERROR: Encountered errors while bringing up the project.
Different Networks
Containers created from docker-compose in different directories also do not share the same network.
$ docker network ls
NETWORK ID NAME DRIVER SCOPE
4a4af52e89cd red2_default bridge local
57695428bd9d redis_default bridge local
Usecase
My usecase for that szenario:
Call docker-compose from different deployment jobs.
Start containers for testing
Questions
Why is there the directory dependency? Is there an option to switch it off?
Does docker ps show which directory was used?
Answer for 1:
The directory name is used as the default project name.
You should better specify the project name:
docker-compose -p myproject up --force-recreate -d
Question 2 still open
Is it possible to pull and start all containers defined in docker-compose.yml? I'm trying to execute docker-compose up -d my/image, where my/image is a repo on DockerHub, but it says "Can't find docker-compose.yml". I also tried first to pull the image using docker pull my/image with the same result
UPD: The image https://hub.docker.com/r/gplcart/core/, source - https://github.com/gplcart/docker-core
SOLVED: It seems docker-compose does not work that way I want. I need to create a directory manually, place docker-compose.yml there, then run docker-compose up.
https://docs.docker.com/compose/wordpress/#define-the-project
I expected that running docker-compose up -d repo/image is enough to download and run all defined containers
To pull an image use docker-compose pull <service_name>, where service_name is one of the services listed in your docker-compose.yml file
The docker pull my/image fails, but should fail with a different error than you noted (you posted a compose error)
In your example, my/name is not a valid service name because you can't use a / in the service name. Compose would give you a different error.
It's unclear to me what my/name represents (assuming you replaced it with something locally).
If you post your docker-compose.yml it would help determine what the correct docker and docker-compose commands should be.
Try logging in to Docker Hub so that Docker Compose knows you want to pull images from there.
From the command line ...
docker login
You will be prompted for a username and password. Once authenticated, compose should pull your images from Docker Hub when running docker-compose up.
Also, you need to run docker-compose up from the same directory where your docker-compose.yml file is. Looking at your docker-compose.yml file on Github, it looks like you are missing a few lines. You need to specify the version, and gplcart, db and phpmyadmin should be under services.
version: '3'
services:
gplcart:
build: .
links:
- db
ports:
- 8080:80
db:
image: mariadb:10.2
environment:
MYSQL_DATABASE: test
MYSQL_ROOT_PASSWORD: test
ports:
- 3306:3306
phpmyadmin:
image: phpmyadmin/phpmyadmin:4.7
links:
- db
ports:
- 8181:80
Make sure docker and docker-compose binaries coming from the same package manager. E.g.
$ which -a docker docker-compose
/snap/bin/docker
/snap/bin/docker-compose
In other words, if you've installed Docker from a Snap, docker-compose binary should be already included (ls /snap/docker/current/bin/). When using Apt repository, docker-compose can be installed separately, so don't interchange binaries between Snap with Apt, as well don't mix docker with docker.io package on Apt.
The error Can't find docker-compose.yml indicates that you are not currently in the directory with your docker-compose.yml file, or that you have named the file something different. If you have named the file something different, including a different case or extension, you can either rename the file, or run docker-compose -f your_filename.yml up to pass a different file for docker-compose to parse. If you are not in the directory, make sure to cd into that directory before running docker-compose commands.
docker-compose acts based on your local docker-compose.yml file. Pulling a third-party image with docker-compose is usually useful when, instead of executing separate docker commands (in order to pull an image or deploy your app, etc etc), you want to define your architecture in a more structured way like:
My docker-compose.yml file:
version: '3'
services:
containerA:
image: gplcart/core
containerB:
build: .
# go on defining the rest ...
and deploying with:
docker-compose build && docker-compose up -d
Here is the simplest working example of docker-compose.yml file:
version: '3'
services:
hello-world:
image: hello-world
Which should produce the following results:
$ docker-compose up
Creating network "docker_default" with the default driver
Creating docker_hello-world_1 ... done
Attaching to docker_hello-world_1
hello-world_1 |
hello-world_1 | Hello from Docker!
hello-world_1 | This message shows that your installation appears to be working correctly.
hello-world_1 |
hello-world_1 | To generate this message, Docker took the following steps:
hello-world_1 | 1. The Docker client contacted the Docker daemon.
hello-world_1 | 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
hello-world_1 | (amd64)
hello-world_1 | 3. The Docker daemon created a new container from that image which runs the
hello-world_1 | executable that produces the output you are currently reading.
hello-world_1 | 4. The Docker daemon streamed that output to the Docker client, which sent it
hello-world_1 | to your terminal.
hello-world_1 |
hello-world_1 | To try something more ambitious, you can run an Ubuntu container with:
hello-world_1 | $ docker run -it ubuntu bash
hello-world_1 |
hello-world_1 | Share images, automate workflows, and more with a free Docker ID:
hello-world_1 | https://hub.docker.com/
hello-world_1 |
hello-world_1 | For more examples and ideas, visit:
hello-world_1 | https://docs.docker.com/get-started/
hello-world_1 |
docker_hello-world_1 exited with code 0
In case of problems, use the following commands which can help to track down the problem:
docker-compose config - Validate configuration file.
docker-compose logs - Check the latest logs.
docker info - Check system-wide information.
sudo strace -fe network docker-compose up - Debug the network issues.
journalctl -u docker.service - Check the logs of Docker service.
When I run docker-compose up it logs some information to the terminal and I would like to know where this information is coming from and how I might log to it.For example I would like to output each request in a php application within the container. I have tried to look online including the docker docs but have had no luck.
The output in docker-compose is the stdout/stderr from the command the container runs. You see this with docker run if you don't detach, and you can get this from docker logs on a container you're detached from or docker-compose logs from a compose submitted group of containers.
Edit: evidence of this behavior:
$ cat docker-compose.hello-world.yml
version: '2'
services:
hello-world:
image: busybox
command: "echo hello world"
$ docker-compose -f docker-compose.hello-world.yml up
Creating test_hello-world_1
Attaching to test_hello-world_1
hello-world_1 | hello world
test_hello-world_1 exited with code 0