how can i mount data from oracle docker container? - oracle

i just want to start an oracle docker container with docker-compose.yml.
that works so far, till i added a folder to sync/mount/whatever from the container.
problem 1: if the folder on the host is missing - docker doesn't mount anything
problem 2: a empty folder is getting ignored by git - so i added an empty file .emptyfileforgit
So if i now start my docker-compose up, docker mounts the folder with my fake file to the oracle container, and so the database is "broken".
docker compose file:
version: "3"
services:
mysql_db:
container_name: oracle_db
image: wnameless/oracle-xe-11g:latest
ports:
- "49160:22"
- "49161:1521"
- "49162:8080"
restart: always
volumes:
- "./oracle_data:/u01/app/oracle/oradata"
- "./startup_scripts:/docker-entrypoint-initdb.d"
environment:
- ORACLE_ALLOW_REMOTE=true
Question: how can i get rid of this behaviour?
With a mysql container that works fine...
Thanks a lot!

By using volume , folder/path/in/host : folder/path/in/container , the data in the container folder is mapped to provided location in the host. Initially the db data is empty, that is why your host folder does not contain any data. And do not put mock-invalid data in the db folder in your container. Because it will corrupt your db. If you want to add dump db data, just put it in the folder of your host folder, it will mapped to the path in your container

You need to copy files in /0u1/app/oracle/oradata
then you can access it out of container in your system in path ./orcle_data location.

Related

How to mount a NFS file share inside a Windows Docker Container

I am running Docker on a Windows Server 2022.
I need to start a Windows Container - must be a windows container because I am porting a Net Framework App that cannot run on Linux.
My Windows Container needs to write uploaded files to a network share.
I have read lots of discussion, but I could only find example on Linux containers.
Currently I am trying using a Docker Compose file. This is the compose file:
version: "3.9"
services:
web:
image: misterpanel
ports:
- "80:80"
volumes:
- misterpanel_images:/inetpub/wwwroot/Img
volumes:
misterpanel_images:
driver: local
driver_opts:
type: cifs
o: username=<myysernane>,password=<mypassword>,rw,domain=<mydomain>
device: "\\\\<server-ip-address>\\<files-share>"
Misterpanel image was created FROM mcr.microsoft.com/dotnet/framework/aspnet
When running docker-compose up, I am getting the following error:
PS C:\Users\Administrator\docker> docker-compose up
Creating volume "docker_misterpanel_images" with local driver
ERROR: create docker_misterpanel_images: options are not supported on this platform
I have also tryed to map the network drive at the host, and then mount the bind when starting the container like this:
docker run -p 80:80 --dns 8.8.8.8 --mount type=bind,source=z:\,target=c:\inetpub\wwwroot\Img misterpanel
But then I get this error ( even with Z drive working at the host ):
docker: Error response from daemon: invalid mount config for type "bind": bind source path does not exist: z:.
I have tryed all the possible sintaxes for the source ( \Z\ and //Z/ for example )
I could only mount binds on the Windows Container to the local C: drive.
Does anyone has ever mounted a bind to a file share inside a Windows Container?
Any help will be appreciated.
Thanks,

Unable to mount docker folder into host using docker-compose

I'm using a docker container to run cucumber test, after the test finished it will generate a report, I want to copy the report to my host machine.
Have a report folder at the root of my project and create a test folder in Dockerfile and copy all the files into the container.
Expect: copy reports from container's /test/report folder to host's /report folder
docker-compose:
version: '3'
services:
test:
build:
context: .
args:
xx : "xxx"
volumes:
- ./report:/test/report
Dockerfile:
RUN mkdir /test
WORKDIR /test
COPY . /test
RUN /test/testing.sh
have other configuration in Dockerfile but not related to volume/mount, so didn't post it here.
There should be three reports in the report folder.
Inside the container, the reports can be seen at /test/report after the test, and if the /report in my host not null, it will override the reports in the container. But the volume doesn't work in reverse order.
Running this on a windows machine currently.
Sounds like you want a bind mount.
Also it is normally best to post your whole docker-compose file just so it's easier to debug/reproduce/help.
Try explicitly setting the volume as a bind mount and see how you go:
- type: bind
source: ./report
target: /test/report
https://docs.docker.com/compose/compose-file/compose-file-v3/#volumes

Create docker image with named/host volume for spring boot application

I have spring boot application which I am trying to dockerize for the first time. I am using docker version 20.10.1 and my host pc is ubuntu 20.04
for this spring boot application, I have a data directory , which has data created when the application is running. I want to access this data from the host operating system. That is why I am using volume.
When I try to mount my container to named volume or to a host volume, but it always create anonymous volume regardless of the command I type.
Here is my docker file.
FROM openjdk:15
COPY target/lib/* /usr/src/app/lib/
COPY target/core-api-7.3.6.jar /usr/src/app/lib/core-api-7.3.6.jar
COPY config/application.properties /usr/src/app/config/application.properties
COPY data/poscms/config/* /usr/src/app/data/poscms/config/
WORKDIR /usr/src/app
ENTRYPOINT ["java", "-jar", "lib/core-api-7.3.6.jar"]
VOLUME /usr/src/app/data
/usr/src/app/data this is the directory where core-app.jar application will create its runtime data, I need to access these data from my host pc
Following is the command for building the image
docker build -t core-app:5.0 .
then I create image using following command
docker run -it -d -p 7071:7071 core-app:5.0 -v /home/bob/data/:/usr/src/app/data
when I check the volumes by running following command
docker volume ls
I can see anonymous volume being created by this container
and my host path which is /home/kapila/data/ is empty and container data is not written to host path.
I experience the same behaviour with named volume as well.
I created a named volume using following command
docker volume create tmp
docker run -it -d -p 7071:7071 core-app:5.0 -v tmp:/usr/src/app/data
and still docker create anonymous volume and data is not written to tmp volume
my host PC is ubuntu pc. Could someone point out what I am doing wrong here
I do something like this:
In your project root , have these files pertaining to docker as required:
1. DockerFile 2.docker-compose.yml 3. docker-env-preview.env
DockerFile content
FROM openjdk:8-jdk-alpine
ARG jarfilepath
RUN mkdir /src
WORKDIR /src
VOLUME /src/tomcat
ADD $jarfilepath yourprojectname.jar
docker-compose.yml content
version: '3'
services:
project-name:
container_name: project-name-service
build:
context: .
args:
jarfilepath: ./target/project-0.0.1.jar
env_file:
- docker-env-preview.env
ports:
- "8831:8831"
- '5005:5005'
networks:
- projectname_subnet
command: java -jar -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 projectname.jar --spring.profiles.active=preview
networks:
project-name_subnet:
external: true
docker-env-preview.env
This file will contain your environment variables values. The applicaiton.properties can read this file to fetch the values, like buildserver.ip=${BUILD_SERVER_DOMAIN}. Basically you define what you want need . Like the example below.
GARBABE_SERVER_DOMAIN=h-db-preview
GARBABE_SERVER_PORT=5422
GARBABE_DB=projectdb
GARBABE_USER=user
GARBABE_PASSWORD=pwd
JPA_DDL_AUTO=validate
JPA_DIALECT=org.hibernate.dialect.PostgreSQLDialect
JPA_SHOW_SQL=false
JPA_SE_SQL_COMMENTS=true
JPA_FORMAT_SQL=false
JPA_NON_CONTEXTUAL_CREATION=true
APP_NAME=project-name-service
BUILD_SERVER_METHOD=http
BUILD_SERVER_DOMAIN=7.8.9.4
Commands to execute :
mvn clean package (if you use maven )
docker-compose up -d --build ( execute docker ps -> check the details on the running container),
To view the logs : sudo docker logs <project-name-service> -f
To get into the container console, docker exec -it <project-name-service> bash
I was able to fix the issue, and only change I did, to make it work, is that, to change the base image from
FROM openjdk:15
to
FROM adoptopenjdk/openjdk15:ubi
and now named and host volume mounts are working as expected. I am not sure what is wrong with official openjdk:15 image.

Why are files copied to mounted folder from inside the container not appearing in the host folder?

When I mount a host folder to my neo4j container the files from in that folder appear inside the containers directory and things work. However files that are inside the containers directory do not appear in the corresponding host folder - like the config file inside the container, located in the mounted conf folder.
version: "3"
services:
cneo4j:
image: neo4j:3.3.5
container_name: cneo
ports:
- "7474:7474"
- "7687:7687"
environment:
- VIRTUAL_PORT=80
- VIRTUAL_HOST=db.localhost.vm
- VIRUAL_ENABLE_SSL=True
- LETSENCRYPT_HOST=db.localhost.vm
- LETSENCRYPT_EMAIL=email#example.com
- CERT_NAME=db.localhost.vm
volumes:
- /c/Users/moeter/cmcr/data/graph_main/neo4j/data:/data:rw
- /c/Users/moeter/cmcr/data/graph_main/neo4j/logs:/logs:rw
- /c/Users/moeter/cmcr/data/graph_main/neo4j/conf:/conf:rw
restart: always
I am using Docker Toolbox for Windows.
A host volume will always map to the contents of the host directory, there is no merging of contents from the image or initialization of the host directory from the image. The process of populating the host directory has to be done by your container entrypoint or command. If there's initial data you want to load, that will need to be saved elsewhere in the image since you cannot access the image folder contents of they are hidden under a volume mount.

Docker compose - share volume Nginx

I just want to test Docker and it seems something is not working as it should. When I have my docker-compose.yml like this:
web:
image: nginx:latest
ports:
- "80:80"
when in browser I run my docker.app domain (sample domain pointed to docker IP) I'm getting default nginx webpage.
But when I try to do something like this:
web:
image: nginx:latest
volumes:
- /d/Dev/docker/nginx-www/nginx/html/:/usr/share/nginx/html/
ports:
- "80:80"
when I run:
docker-compose up -id
when I run same url in browser I'm getting:
403 Forbidden
nginx/1.9.12
I'm using Windows 8.1 as my host.
Do I do something wrong or maybe folders cannot be shared this way?
EDIT
Solution (based on #HemersonVarela answer):
The volume I've tried to pass was in D:\Dev\docker location so I was using /d/Dev/docker at the beginning of my path. But looking at https://docs.docker.com/engine/userguide/containers/dockervolumes/ you can read:
If you are using Docker Machine on Mac or Windows, your Docker daemon has only limited access to your OS X or Windows filesystem. Docker Machine tries to auto-share your /Users (OS X) or C:\Users (Windows) directory.
so what I needed to do, is to create my nginx-ww/nginx/html directory in C:\users\marcin directory, so I ended with:
web:
image: nginx:latest
volumes:
- /c/Users/marcin/docker/nginx-www/nginx/html/:/usr/share/nginx/html/
ports:
- "80:80"
and this is working without a problem. Files are now shared as they should be
If you are using Docker Machine on Windows, docker has limited access to your Windows filesystem. By default Docker Machine tries to auto-share your C:\Users (Windows) directory.
So the folder .../Dev/docker/nginx-www/nginx/html/ must be located somewhere under C:\Users directory in the host.
All other paths come from your virtual machine’s filesystem, so if you want to make some other host folder available for sharing, you need to do additional work. In the case of VirtualBox you need to make the host folder available as a shared folder in VirtualBox.
You have to set a command to copy your nginx.conf into the nginx container:
Dockerfile:
FROM nginx
COPY nginx.conf /etc/nginx/nginx.conf`
Creat a dir name it nginx and put the Dockerfile & nginx.conf there, then you have to set a build:
docker-compose.yml:
web:
image: nginx:latest
build :./nginx/
volumes:
- /d/Dev/docker/nginx-www/nginx/html/:/usr/share/nginx/html/
ports:
- "80:80"
Then build your containers with : sudo docker-compose build

Resources