How is this Docker volume's route mapped in my host machine? - macos

In my docker-compose.yml file, I have this container definition:
elasticsearch:
image: elasticsearch:2.3.5
volumes:
- esdata:/usr/share/elasticsearch/data
ports:
- 9200:9200
- 9300:9300
I cannot find elasticsearch data because I don't know where is esdata located. How is it mapped in my host machine? Where is that directory? I'm running it on a MacOS High Sierra.

the mapping is HOST:CONTAINER
If your volume works, the esdata directory is in the same directory as your docker-compose file.
In my docker-compose file I write "./:/exemple/of/route"
You can check volumes with a docker inspect [container name]
You can also do this find / -type d -name 'esdata' to find the directory on your host

Related

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.

Docker Logstash, Failed to fetch pipeline configuration

On my windows machine i run this docker compose file:
docker-compose.yml:
version: '3.0'
services:
logstash:
image: logstash:latest
command: -f ./etc/logstash/config/ --log.level debug
volumes:
- ./config/:/etc/logstash/config/
- ./pipeline/:/etc/logstash/pipeline/
logstash.yml:
http.host: "0.0.0.0"
path.config: /etc/logstash/pipeline/logstash.conf
path.settings: /etc/logstash/config/logstash.yml
This gives the error:
Failed to fetch pipeline configuration {:message=>"No config files found: ./etc/logstash/config/. Can you make sure this path is a logstash config file?"}
What can be the problem? This is my directory structure on my Win10 machine:
/docker
/config
/logstash.yml
/pipeline
/logstash.conf
-- Edit
Problem solved with the next config file:
logstash:
image: logstash:latest
command: -f ./etc/logstash/pipeline/
volumes:
- ./config/:/etc/logstash/config/
- ./pipeline/:/etc/logstash/pipeline/
You defined to mount ./config folder of the host machine to /etc/logstash/config/ inside container according to the part of your docker-compose.yaml file:
volumes:
- ./config/:/etc/logstash/config/
The ./config folder path on the host machine is relative path to the location of docker-compose.yaml file.
The docker-compose.yaml is located in ./docker/config folder, so there is no .config folder inside it.
To achieve what you want just move docker-compose.yaml file to one level up:
mv docker-compose.yaml ../
File should be located inside ./docker folder:
/docker
docker-compose.yaml
/config
/logstash.yml
/pipeline
/logstash.conf
You are mounting to wrong image directory.
Logstas docker Image directory layout is as follows:
/usr/share/logstash/config
/usr/share/logstash/pipeline
and like this for bin, data etc.
Refer it for more: Logstash Docker Directory Layout

Docker (for Windows) does not mount volume

I'm trying to mount a directory with configuration files in my docker-compose.yml.
In my case it is logstash, which tells me the mounted directory is empty.
Loading a bash and ls -la in the parent directory shows that the pipeline directory is empty and is owned by root.
One weird thing is, that it worked a few days ago.
docker-compose.yml:
version: '3'
services:
logstash:
image: docker.elastic.co/logstash/logstash:5.6.3
ports:
- 5000:5000
- 8989:8989
volumes:
- C:/PROJECT_DIR/config/logstash/pipeline/:/usr/share/logstash/pipeline/
I found it better to try around with docker itself, as it gives more feedback
docker run --rm -it -v C:/PROJECT_DIR/config/logstash/pipeline/:/usr/share/logstash/pipeline/ docker.elastic.co/logstash/logstash:5.6.3
From here and some googling I found out I had to reset my shared drives credentials under "Docker for Windows" -> Settings... -> Shared Drives, because I had changed my windows domain user password.
If you changed your system username or password then you need to re-apply the credentials to get the volume mount working.

how can i mount data from oracle docker container?

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.

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