Setup Oracle database with docker-compose - oracle

I want to start a Docker-container with Oracle XE and then run an SQL script (setup_database.sql) to create some tables in docker-compose.
How can I integrate the following commands into my docker-compose:
docker run -d -p 49161:1521 -v "$PWD":/duo --name duodb --hostname duodb --network duo-test -e ORACLE_ALLOW_REMOTE=true wnameless/oracle-xe-11g-r2
Run a terminal in container:
docker exec -ti duodb /bin/bash
go into the right directory:
cd duo/sql
Kick off the setup_database script:
sqlplus system/oracle#xe #setup_database
I've tried to do run this:
oracle:
container_name: duodb
image: wnameless/oracle-xe-11g-r2
ports:
- '49161:1521'
volumes:
- .:/duo
command: ["/bin/bash", "-c", "sqlplus system/oracle#xe #setup_database"]
environment:
- ORACLE_ALLOW_REMOTE=true
But this outputs the following error:
Creating network "duo_default" with the default driver
Creating duodb
Creating duomail
Creating duolocal
Attaching to duomail, duodb, duolocal
duomail | MailDev webapp running at http://0.0.0.0:80
duomail | MailDev SMTP Server running at 0.0.0.0:25
duodb | /bin/bash: sqlplus: command not found
duodb exited with code 127
duolocal | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.20.0.3. Set the 'ServerName' directive globally to suppress this message
duolocal | [Fri Nov 15 08:17:55.944907 2019] [ssl:warn] [pid 1] AH01909: 172.20.0.3:443:0 server certificate does NOT include an ID which matches the server name
duolocal | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.20.0.3. Set the 'ServerName' directive globally to suppress this message
duolocal | [Fri Nov 15 08:17:55.977329 2019] [ssl:warn] [pid 1] AH01909: 172.20.0.3:443:0 server certificate does NOT include an ID which matches the server name
duolocal | [Fri Nov 15 08:17:55.980390 2019] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.38 (Debian) PHP/7.1.32 OpenSSL/1.1.1d configured -- resuming normal operations
duolocal | [Fri Nov 15 08:17:55.980423 2019] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'

I am not that docker expert, but as far as I know, the network is automatically created with all containers inside a docker-compose file, therefore you do not need the network. Furthermore, you can name the service so I think container-name is also not needed. In which version do you start the compose file? You could try something like this
version: "3"
services:
duodb:
image: wnameless/oracle-xe-11g-r2
ports:
- 49161:1521
volumes:
- .:/duo
environment:
ORACLE_ALLOW_REMOTE=true
MYSQL_ROOT_USER: root
MYSQL_ROOT_PASSWORD: secret
MYSQL_DATABASE: my_database_name

version: "3"
services:
duodb:
image: wnameless/oracle-xe-11g-r2
ports:
- 49161:1521
volumes:
- .:/duo
environment:
- ORACLE_ALLOW_REMOTE=true
- MYSQL_ROOT_USER=root
- MYSQL_ROOT_PASSWORD=secret
- MYSQL_DATABASE=my_database_name

Related

Host timezone not reflect on spring-boot docker container

I'm trying to set a localtime to my docker container as the same as my localtime locally to use on a spring-boot application when save a data.
spring-boot app:
...
cpoWorkflowExecution.setStartDate(LocalDateTime.now());
...
Local localtime:
[ainacio#brsp1nf01 cpo-dockers]$ ls -l /etc/localtime
lrwxrwxrwx. 1 root root 39 Oct 6 07:42 /etc/localtime -> ../usr/share/zoneinfo/America/Sao_Paulo
Local timezone:
[ainacio#brsp1nf01 cpo-dockers]$ cat /etc/timezone
America/Sao_Paulo
Container localtime didn't work:
root#ffbd68eeaccd:/# ls -l /etc/localtime
lrwxrwxrwx. 1 root root 27 Nov 17 13:37 /etc/localtime -> /usr/share/zoneinfo/Etc/UTC
Container timezone worked:
root#ffbd68eeaccd:/# cat /etc/timezone
America/Sao_Paulo
Docker-compose:
version: '3'
services:
cpo-executor:
container_name: cpo-executor
image: .../cpo-executor:1.103.3.1
ports:
- 8879:8879
environment:
- TZ=America/Sao_Paulo
volumes:
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
networks:
- cpo-network
depends_on:
- cpo-config-server
I've also tried to set TZ environment variable but it didn't work as well.
I'm generating the docker image using spring-boot maven plugin:
mvn spring-boot:build-image -DskipTests -Dspring-boot.build-image.imageName=.../cpo-executor:1.103.3.1
What am I missing?

Problem to access mysql using phpadmin interface (UBUNTU 20.04)

I'm a beginner in docker. I started a docker compose with mysql and phpmyadmin to do a simple test, but I have some problem to access MySQL server using phpMyAdmin interface.
I'm using UBUNTU 20.04
When I try access MySQL server with credentials in phpMyAdmin (http://localhost:9090/) I get this error:
mysqli::real_connect(): php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution
mysqli::real_connect(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution
Follow below also the docker log with error regardins phpmyadmin
phpmyadmin_1 | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.18.0.4. Set the 'ServerName' directive globally to suppress this message
phpmyadmin_1 | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.18.0.4. Set the 'ServerName' directive globally to suppress this message
phpmyadmin_1 | [Sun Dec 19 12:12:17.249145 2021] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.38 (Debian) PHP/7.4.20 configured -- resuming normal operations
phpmyadmin_1 | [Sun Dec 19 12:12:17.249624 2021] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'
Could you please help me understand if I need do some setup in my Ubuntu environment or if the docker-compose file is wrong?
Follow bellow my docker-compose.yaml
version: '3.5'
services:
mysql:
image: mysql
command: --default-authentication-plugin=mysql_native_password
ports:
- 3306:3306
environment:
MYSQL_USER: root
MYSQL_ROOT_PASSWORD: 123456
volumes:
- mysql:/var/lib/mysql
security_opt:
- seccomp:unconfined
phpmyadmin:
image: phpmyadmin/phpmyadmin:latest
links:
- mysql
ports:
- 9090:80
environment:
- PMA_ARBITRARY=1
rabbitmq:
image: rabbitmq:3.8.3-management
ports:
- 5672:5672
- 15672:15672
volumes:
- $PWD/storage/rabbitmq1:/var/lib/rabbitmq
environment:
- RABBITMQ_ERLANG_COOKIE=This_is_my_secret_phrase
- RABBITMQ_DEFAULT_USER=admin
- RABBITMQ_DEFAULT_PASS=admin
volumes:
mysql:
rabbitmq:
phpmyadmin:
Your phpMyAdmin container doesn't know where to find the MySQL database server. You need to:
link the MySQL container (you already did that),
supply a config file to phpMyAdmin, or
provide proper connection details when logging in to phpMyAdmin.
All options of the Docker image are documented in phpMyAdmin Docker hub page.
In case of your specific docker-compose file, the connection details that work are:

Docker container closes immediately after start

I want to setup learning development container for VSCode on my Windows 10 machine, but when I press "Open Folder in a Container" in VSCode I get an error:
[2020-11-24T10:21:22.963Z] [PID 8208]
[2020-11-24T10:21:23.070Z] [PID 8208] [8794 ms] Start: Run: docker ps -q -a --filter label=com.docker.compose.project=lecture2 --filter label=com.docker.compose.service=development
[2020-11-24T10:21:23.762Z] [PID 8208] [9486 ms] Start: Run: docker inspect --type container 03d485c0d0b0
[2020-11-24T10:21:24.630Z] [PID 8208] [10354 ms] Start: Inspecting container
[2020-11-24T10:21:24.631Z] [PID 8208] [10355 ms] Start: Run: docker inspect --type container 03d485c0d0b08ae5af7bc81124f9205d933ce77441829cfcf176a6dd767ab291
[2020-11-24T10:21:25.656Z] [PID 8208] [11380 ms] Start: Run: docker exec -i -u root -e VSCODE_REMOTE_CONTAINERS_SESSION=663b838f-c06e-4178-ae10-5f48efb218811606213272822 03d485c0d0b08ae5af7bc81124f9205d933ce77441829cfcf176a6dd767ab291 /bin/sh
[2020-11-24T10:21:25.678Z] [PID 8208] [11402 ms] Start: Run in container: uname -m
[2020-11-24T10:21:26.558Z] [PID 8208] [12282 ms] Start: Run in container: cat /etc/passwd
[2020-11-24T10:21:26.558Z] [PID 8208] [12282 ms] Stdin closed!
[2020-11-24T10:21:26.570Z] [PID 8208] [12294 ms] Shell server terminated (code: 1, signal: null)
Error response from daemon: Container 03d485c0d0b08ae5af7bc81124f9205d933ce77441829cfcf176a6dd767ab291 is not running
And if I just issue command:
docker-compose up
The container is started and stopped immediately without any errors in console.
My setting is like this:
Dockerfile:
FROM erlang:latest
WORKDIR /project
CMD tail -f /dev/null
docker-compose.yml:
version: '3'
services:
development:
build:
context: .
volumes:
- ./:/project
- build:/project/_build
- deps:/project/deps
volumes:
build:
deps:
.devcontainer/devcontainer.json:
{
"name": "Erlang dev container",
"service": "development",
"context": "..",
"dockerComposeFile": "..\\docker-compose.yml",
"workspaceFolder": "/project",
"settings": {
"terminal.integrated.shell.linux": "/bin/bash"
},
"extensions": []
}
Why doesn't it work?
PS.
I even changed my Dockerfile like this:
FROM erlang:latest
WORKDIR /project
COPY . .
And my docker-compose.yml to this:
version: '3'
services:
development:
build:
context: .
And it still doesn't work.
PS PS.
But! When after that I changed in devcontainer.json line:
"dockerComposeFile": "..\\docker-compose.yml",
to:
"dockerFile": "..\\Dockerfile",
Only then my folder was opened in the container by VSCode.
But I don't want to COPY . . inside my Dockerfile, I want to add my project's folder as a volume in my docker-compose.yml file. How do I manage this?
I solved my problem by adding tty:true to my docker-compose service definition, like this:
version: '3'
services:
development:
build:
context: .
tty: true
volumes:
- ./:/project

Can't add persistent folder to bitnami/mongodb on windows

I think this might be related to file system incompatibility (nfts/ext*)
How can I compose my containers and persist the db without the container exiting?
I'm using the bitnami-mongodb-image
Error:
Error executing 'postInstallation': EACCES: permission denied, mkdir '/bitnami/mongodb'
mongodb_1 exited with code 1
Full Output:
Recreating mongodb_1 ... done
Starting node_1 ... done
Attaching to node_1, mongodb_1
mongodb_1 |
mongodb_1 | Welcome to the Bitnami mongodb container
mongodb_1 | Subscribe to project updates by watching https://github.com/bitnami/bitnami-docker-mongodb
mongodb_1 | Submit issues and feature requests at https://github.com/bitnami/bitnami-docker-mongodb/issues
mongodb_1 |
mongodb_1 | nami INFO Initializing mongodb
mongodb_1 | mongodb INFO ==> Deploying MongoDB from scratch...
mongodb_1 | Error executing 'postInstallation': EACCES: permission denied, mkdir '/bitnami/mongodb'
mongodb_1 exited with code 1
Docker Version:
Docker version 18.06.0-ce, build 0ffa825
Windows Version:
Microsoft Windows 10 Pro
Version 10.0.17134 Build 17134
This is my docker-compose.yml so far:
version: "2"
services:
node:
image: "node:alpine"
user: "node"
working_dir: /home/node/app
environment:
- NODE_ENV=development
volumes:
- ./:/home/node/app
ports:
- "8888:8888"
command: "tail -f /dev/null"
mongodb:
image: 'bitnami/mongodb'
ports:
- "27017:27017"
volumes:
- "./data/db:/bitnami"
- "./conf/mongo:/opt/bitnami/mongodb/conf"
I do not use Windows but you can definitely try to use a named volume and see if the permission problem goes away
version: "2"
services:
node:
image: "node:alpine"
user: "node"
working_dir: /home/node/app
environment:
- NODE_ENV=development
volumes:
- ./:/home/node/app
ports:
- "8888:8888"
command: "tail -f /dev/null"
mongodb:
image: 'bitnami/mongodb'
ports:
- "27017:27017"
volumes:
- mongodata:/bitnami:rw
- "./conf/mongo:/opt/bitnami/mongodb/conf"
volumes:
mongodata:
I would like to stress this is a named volume, compared to the host volumes you are using. It is the best option for production and you need to be aware that docker will manage and store the files for you so you will not see the files in your project folder.
If you still want to use host volumes (so volumes that write to that location you specify in your project subfolder on the host machine) you need to apply a permission fix, here is an example for mariadb but it will work for mongo too
https://github.com/bitnami/bitnami-docker-mariadb/issues/136#issuecomment-354644226
In short, you need to know what is the user of the filesystem (in the example 1001 is the user id on my host machine for my logged in user) on your host and then chown that folder to this user so the user will be the same on the folder and your host system.
A full example:
version: "2"
services:
fix-mongodb-permissions:
image: 'bitnami/mongodb:latest'
user: root
command: chown -R 1001:1001 /bitnami
volumes:
- "./data:/bitnami"
mongodb:
image: 'bitnami/mongodb'
ports:
- "27017:27017"
volumes:
- ./data:/bitnami:rw
depends_on:
- fix-mongodb-permissions
I hope this helps

How to run elasticsearch via docker compose or swarm mode and install plugin with command

Problem Statement
I have a docker-compose.yml file (v3) that looks like the following:
version: '3'
services:
elastic:
restart: always
image: elasticsearch:2.3.1
command: ["sh", "-c", "./bin/plugin install delete-by-query && ./bin/elasticsearch"]
volumes:
- /home/styfle/esdata:/usr/share/elasticsearch/data
ports:
- 9200:9200
kibana:
restart: always
image: kibana:4.5.4
ports:
- 5601:5601
links:
- elastic:elasticsearch
When I run docker-compose up elastic it appears that the plugin installed correctly, but I get the message "don't run elasticsearch as root".
Creating dev_elastic_1 ... done
Attaching to dev_elastic_1
elastic_1 | -> Installing delete-by-query...
elastic_1 | Trying https://download.elastic.co/elasticsearch/release/org/elasticsearch/plugin/delete-by-query/2.3.1/delete-by-query-2.3.1.zip ...
elastic_1 | Downloading ..DONE
elastic_1 | Verifying https://download.elastic.co/elasticsearch/release/org/elasticsearch/plugin/delete-by-query/2.3.1/delete-by-query-2.3.1.zip checksums if available ...
elastic_1 | Downloading .DONE
elastic_1 | Installed delete-by-query into /usr/share/elasticsearch/plugins/delete-by-query
elastic_1 | Exception in thread "main" java.lang.RuntimeException: don't run elasticsearch as root.
elastic_1 | at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:93)
elastic_1 | at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:144)
elastic_1 | at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:270)
elastic_1 | at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:35)
elastic_1 | Refer to the log for complete error details.
dev_elastic_1 exited with code 74
Question
How can I install the plugin and run as the elasticsearch user instead of root user?
As per the docker-compose architecture and cleanup policies, you cannot run a docker-compose command to initiate a subshell.
You can do some bash and docker changes in your current docker-compose.yml file as below:
version: '3'
services:
elastic:
restart: always
image: elasticsearch:2.3.1
user: ${MY_USER_ID}
command: ["sh", "-c", "./bin/plugin install delete-by-query && ./bin/elasticsearch"]
volumes:
- /home/styfle/esdata:/usr/share/elasticsearch/data
ports:
- 9200:9200
kibana:
restart: always
user: ${MY_USER_ID}
image: kibana:4.5.4
ports:
- 5601:5601
links:
- elastic:elasticsearch
I have added a line user: ${MY_USER_ID} in the above docker-compose.yml file. After this, you need to use the below command to spin up the containers and start elasticsearch:
MY_USER_ID=$(id -u):$(id -g) docker-compose up elastic
Test it and let me know the feedback.

Resources