Retrieve a db_dump from a docker container [duplicate] - docker

This question already has answers here:
How do I retrieve the exact container name started by docker-compose.yml
(3 answers)
How to generate a Postgresql Dump from a Docker container?
(8 answers)
Closed 5 months ago.
Could anyone pls bring some clarification on this:
I have this yaml with several services
version: "3.3"
services:
db:
image: postgres:11.6
restart: always
environment:
ENV1: VAL1
ENV2: VAL2
I need somehow to get the container name to create and retrieve a db_dump file from there. I can't use docker ps cause this happens in a github action. I have this string to do it:
docker exec -d $CONTAINER_ID pg_dump -f $db_dump_file $db_mame && docker cp $CONTAINER_ID:[src_file] [dest_file]
Any suggestions on how to get the $CONTAINER_ID are appreciated.
Thank you in advance

version: "3.3"
services:
db:
image: postgres:11.6
container_name: my_container
This will set a name for your container.

Related

What is wrong with trying to create two instances of docker-compose.yml

I have an idea to up several similar instances with my docker-compose simple mini-project.
docker-compose file:
version: '3.1'
services:
postgres:
build:
context: .
dockerfile: postgres/Dockerfile
environment:
- POSTGRES_PASSWORD=postgres
- POSTGRES_USER=postgres
ports:
- "${PORT_NUMBER}:5432"
Dockerfile:
FROM postgres:9.6
In ./config/.env.dev file I set unique required port number (eg. 5435 for first instance,
5436 for second etc.)
When I up first instance with command:
docker-compose -p instance1 --env-file ./config/.env.dev up
it's OK and I see one new container and one new network instance1_default.
But when I try to up another new instance with command:
docker-compose -p instance2 --env-file ./config/.env.dev up
Docker stuck at this:
Creating network "instance2_default" with the default driver
.. and nothing happens. Yes, I changed port number in env-file before running new instance.
What's wrong with creating new network?
Docker version 20.10.8, build 3967b7d
docker-compose version 1.29.2, build 5becea4c

docker-compose up not starting service

I am trying to get a simple docker-compose file working on windows.
version: "2"
volumes:
db_data: {}
services:
db:
image: mariadb
environment:
MYSQL_ROOT_PASSWORD: test123
volumes:
- db_data:/var/lib/mysql/data
I need to persist the db data. I've created the directory db_data and I found this solution from a github issue: https://github.com/docker-library/mysql/issues/69. I had previously been using mysql 5.6. I'm simply running
docker-compose up -d
when I check
docker ps
I do not get any running processes. Any help with this would be greatly appreciated. I've added the output from running the command below:
PS D:\test-exercise> docker-compose up -d
Starting test-exercise_db_1 ... done

Multiple containers in docker works on same IP [duplicate]

This question already has answers here:
How to get Docker containers to talk to each other while running on my local host?
(4 answers)
Closed 2 years ago.
I want my Docker containers to work on the same IP. Is it possible? I want them to have the same IP address so that they can link to each other through it.
Have a look at https://docs.docker.com/compose/networking/ to learn how containers are made accessible with docker-compose.
The gist of it is that you access containers by the name you've given them in the compose-file. So in that example
version: "3.9"
services:
web:
build: .
ports:
- "8000:8000"
db:
image: postgres
ports:
- "8001:5432"
you can address the hosts as web and db.

How to run a dockercompose file from another dockercompose file?

I have looked at the docker docs for the answer to this question and I dont see it being laid out simply anywhere. I want to start my app in a docker using docker-compose.yml I want that docker-compose.yml to start up other containers defined in another docker-compose.yml file in a different project.
version: '3.4'
#we need network if we want the services to talk to each other
networks:
services:
driver: bridge
services:
jc:
build:
context: .
dockerfile: ./Dockerfile
args:
- PORT=8080
network: host
networks:
- services
image: jc
container_name: jc
ports:
- 8080:8080
How can I edit this file so that I can run another docker-compose.yml file in a different file path when I run this docker-compose.yml file?
After trying the to use the extends option of the docker-compose file and differing variations of its usage I consistently received an error indicating that extends is not supported even after updating to the latest docker version. I did however solve the problem by running this command.
docker-compose -f /path/to/other/docker-compose-file/docker-compose.yml up
I was sure that I had to add something to the docker-compose file so I overlooked this in the docs. But you can read more about it here.
docker-compose docs
This is kind of a hack but you can add another container that starts docker compose with another docker-compose file.
for example:
Docker file for the starter container:
FROM ubuntu:bionic
RUN mkdir -p /compose
WORKDIR /compose
CMD ["docker-compose", "up", "-d"]
The main docker compose file (starts a redis server and the starter container). note the compose binary, docker socket and another docker-compose.yml file are mounted into the starter container:
version: '2.1'
services:
from-main-compose:
image: redis:3
starter:
image: starter:latest
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- /usr/local/bin/docker-compose:/usr/local/bin/docker-compose:ro
- /home/shay/source/composeFromContainer/another-compose/docker-compose.yml:/compose/docker-compose.yml:ro
Second docker compose file:
version: '2.1'
services:
redis-from-container:
image: redis:3
The result is this:
b1faa975df49 redis:3 "docker-entrypoint.s…" 5 minutes ago Up 5 minutes 6379/tcp compose_redis-from-container_1
7edca79d3d99 redis:3 "docker-entrypoint.s…" 5 minutes ago Up 5 minutes 6379/tcp composefromcontainer_from-main-compose_1
Note that if using this hack as it is the services will be placed on different networks so this might need to be tweaked a bit.

Can't set root password for OrientDB using docker-compose

I'm using the latest orientdb docker image in my docker-compose. I need to set the default root password but it's not working. My docker-compose.yml:
orientdb:
image: orientdb
ports:
- "2434:2434"
- "2480:2480"
- "2424:2424"
volumes:
- "/mnt/sda1/dockerVolumes/orientdb:/opt/orientdb/databases"
environment:
- ORIENTDB_ROOT_PASSWORD
I'm currently running:
$ export ORIENTDB_ROOT_PASSWORD=anypw
$ docker-compose up -d
You need to define password in docker-compose:
environment:
- ORIENTDB_ROOT_PASSWORD=anypw
if you want to hide your password from docker-compose you can create docker-compose:
environment:
- ORIENTDB_ROOT_PASSWORD=${ORIENTDB_ROOT_PASSWORD}
I have been able to reproduce your solution and it works:
docker-compose.yml
version: '2'
services:
orientdb:
image: orientdb
ports:
- "2434:2434"
- "2480:2480"
- "2424:2424"
environment:
- ORIENTDB_ROOT_PASSWORD=test
now:
$ docker-compose up -d
Creating network ... with the default driver
Creating test_orientdb_1
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d1f0a4a81222 orientdb "server.sh" 31 seconds ago Up 22 seconds 0.0.0.0:2424->2424/tcp, 0.0.0.0:2434->2434/tcp, 0.0.0.0:2480->2480/tcp test_orientdb_1
User: root
Pass: test
You probably tried to log in, but you have not created database.
Just create one and try to log in.
You have to first run docker-compose down command.
Then you can run the docker-compose up command.
This will remove previous configuration and allow you to connect to the database.

Resources