I'd like to have each app release stored as some kind of container and then have several "server" only containers(DB, web server). How can the cooperation between those containers work?
I can imagine to define some volume in "app" container where the app. binaries will be stored and then use this volume folder as web server's deploy directory in the "server" container.
How will the process to update the application version work? How can I "bind" multiple binaries with one "server" container?
More generally I can imagine to deploy like this
"deploy some-version-releasecontainer to serv1, serv2, serv3", maybe docker is not the proper tooling and I will need some more abstract management like Swarm, kubernate etc. But the main point is to create application binary as selfstanding, read-only entity known to the eco-system.
Maybe you need a docker-compose to make your containers interact on a virtual network (but you can still share resources and volumes). I'll post a simple example here.
The docker-compose is the following:
version: '2'
services:
myapp_service1:
image: myapp_image1:latest
networks:
mynetwork:
aliases:
- myalias1
depends_on:
- mysql
expose:
- 8080
volumes:
- /opt/myapp/logs:/jboss-as-7.1.1.Final/logs
environment:
- "JAVA_OPTS=-Xms64m -Xmx128m -XX:MaxPermSize=128m -Djava.net.preferIPv4Stack=true"
- "db=mysql.myapp"
volumes_from:
- myapp_volume
myapp_service2:
image: myapp_image2:latest
networks:
mynetwork:
aliases:
- myalias2
depends_on:
- mysql
expose:
- 8080
volumes:
- /opt/myapp/logs:/jboss-as-7.1.1.Final/logs
environment:
- "JAVA_OPTS=-Xms64m -Xmx128m -XX:MaxPermSize=128m -Djava.net.preferIPv4Stack=true"
- "db=mysql.myapp"
volumes_from:
- myapp_volume
myapp_volume:
container_name: myapp_volume
image: myapp_volume_image:latest
mysql:
image: mysql
networks:
mynetwork:
aliases:
- mysql.myapp
expose:
- 3306
ports:
- "13306:3306"
volumes:
- /opt/myapp/mysql:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: root
networks:
mynetwork:
driver: bridge
Here we have four containers. The first two are sample applications sharing the same volume. The volume is defined just below the applications and in the end we have a container which runs a simple MySql DB.
The Dockerfile for the shared volume container is that one:
FROM alpine
VOLUME /jboss-as-7.1.1.Final/mydir/config
CMD /bin/sh -c "while true; do sleep 1; done"
The docker compose is a yml file, let's say my-docker-compose.yml. To run it you have to type this in the terminal:
docker-compose -f path/to/compose/my-docker-compose.yml up -d
Of course, the images should already be built.
Related
I have an java spring / hibernate application and I cant create a connection beween the mysql and java containers. When I start just the mysql Container and run the java application manualy in CMD it works fine. But once the java application runs in a container I get the following problem:
bookAPI | com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
bookAPI |
bookAPI | The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
bookAPI | at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174) ~[mysql-connector-java-8.0.21.jar!/:8.0.21]
bookAPI | at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64) ~[mysql-connector-java-8.0.21.jar!/:8.0.21]
If I understand the error correctly the java container can send to the mysql container but not the other way around. I have linked the java container to the mysql container. Anyone knows how to connect these containers correctly?
My docker-compose.yml looks like this:
version: '3'
services:
db:
image: mysql:5.7
container_name: mysql
environment:
MYSQL_ROOT_PASSWORD: aaaaaa
MYSQL_DATABASE: bookAPI
MYSQL_USER: aaaaaa
MYSQL_PASSWORD: aaaaaa
ports:
- 3306:3306
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: phpmyadmin
links:
- db
environment:
PMA_HOST: db
PMA_PORT: 3306
PMA_ARBITRARY: 1
restart: always
ports:
- 8081:80
java:
container_name: bookAPI
image: openjdk:8
depends_on:
- db
volumes:
- ./:/app
working_dir: /app
command: bash -c "cd /app && java -jar bookAPI.jar"
stdin_open: true
tty: true
ports:
- 8080:8080
links:
- db
You can also directly override the applications.properties with docker-compose environment variables like this :
java:
container_name: bookAPI
image: openjdk:8
volumes:
- ./:/app
working_dir: /app
command: bash -c "cd /app && java -jar bookAPI.jar"
stdin_open: true
tty: true
environment:
spring.datasource.url="jdbc:mysql://db:3306/bookAPI""
links:
- db
ports:
- 8080:8080
I would recomment you tu use depends_on db instead of links
depends_on:
- db
Okay, I solved the problem. To connect the spring application with another docker container you need to change the application.properties url value from localhost or ip to the docker maysql container name. Thats tricky while running it localy or run maven install so the best pracice is to overwrite it while starting the application in container.
java:
container_name: bookAPI
image: openjdk:8
volumes:
- ./:/app
working_dir: /app
command: bash -c "cd /app && java -jar bookAPI.jar --spring.datasource.url="jdbc:mysql://db:3306/bookAPI""
stdin_open: true
tty: true
links:
- db
ports:
- 8080:8080
I've made a war to run on my tomcat server in a Docker container. The servlet runs fine in eclipse, but when I have compiled it put it in my Docker it isn't loading in the required classes properly.
Project structure and manifest file
When I try and access the servlet using my browser I get this error.
Error in browser
I went into the Docker container and checked that gurobi.jar is still in WEB-INF/lib/ and it is.
I don't know why this wouldn't be able to find the jar, as it works fine when it's in Eclipse.
docker-compose.yml
version: '3'
services:
db:
image: mysql:5.7
ports:
- '3306:3306'
environment:
MYSQL_DATABASE: 'projectdb'
MYSQL_USER: ''
MYSQL_PASSWORD: ''
MYSQL_ROOT_PASSWORD: ''
web:
build:
context: .
dockerfile: Dockerfile
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
- /var/run/docker.sock:/var/run/docker.sock
ports:
- "8000:8000"
depends_on:
- db
tomcat:
image: tomcat
ports:
- "8080:8080"
volumes:
- ./GurServ.war:/usr/local/tomcat/webapps/GurServ.war
java:
image: bitnami/java:latest
volumes:
- .:/app
- .:/code
Dockerfile
FROM python:3
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
COPY requirements.txt /code/
RUN pip install -r requirements.txt
COPY . /code/
EXPOSE 8000
CMD exec gunicorn djangoapp.wsgi:application - bind 0.0.0.0:8000 - workers 3
Project structure
...
Java Resources
src
...
WebContent
META-INF
MANIFEST.MF
WEB-INF
gurobi-javadoc.jar
gurobi.jar
I've just started to use Docker and I don't know why the Wildfly's docker container doesn't have the latest files even though it copies the war. I have a JS file which I've changed things in it, but whenever I access 127.0.0.1:8080/static/js/myjs.js I still get the older one even though I've sudo mvn clean install the app and then build the image.
I've a docker-compose file which looks like this:
version: "3"
services:
app:
build:
context: .
dockerfile: ./docker/docker-app/Dockerfile
ports:
- "8080:8080"
links:
- "db:task_book_db"
depends_on:
- "db"
db:
image: mysql:5.7.22
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=sample_db
- MYSQL_USER=sample_usr
- MYSQL_PASSWORD=sample_pw
ports:
- "3306:3306"
start_dependencies:
image: dadarek/wait-for-dependencies
depends_on:
- "db"
I do sudo docker-compose run --rm start_dependencies && sudo docker-compose up --build app and whenever I've changed something, I just stop the app container then I do sudo docker-compose up --build app again. I've read about volumes but I'm not sure how to use them yet.
As mentioned in the comments:
This issue might be because of browser cache. Try accessing the 127.0.0.1:8080/static/js/myjs.js
after clearing the cache.
I developed a Java EE application on Eclipse for a school project and try to use it in localhost through Tomcat, all using Docker.
My problem is the url, I would like that when I launch my application with Docker, I can access it at http://localhost:8080. Currently, I have to go to the link http://localhost:8080/Epitech_Dashboard/.
Would it be possible to have access to the application directly on http://localhost:8080?
Ps: I saw a similar question on slack but it does not solve my problem because she does not handle the problem with docker-compose.
Here's my Dockerfile and my docker-compose.yml
Dockerfile:
FROM java:8
EXPOSE 8080
ADD /#.war #.war
ENTRYPOINT ["java", "-jar", "#.war"]
docker-compose.yml
version: '2'
services:
web:
image: tomcat:7
environment:
JDBC_URL: jdbc:mysql://db:3306/example_db?connectTimeout=0&socketTimeout=0&autoReconnect=true
JDBC_USER: example_db_user
JDBC_PASS: example_db_pass
ports:
- '8080:8080'
volumes:
- ./Epitech_Dashboard.war:/usr/local/tomcat/webapps/Epitech_Dashboard.war
links:
- db
db:
image: mysql:latest
hostname: db
environment:
MYSQL_ROOT_PASSWORD: nimda
MYSQL_DATABASE: example_db
MYSQL_USER: example_db_user
MYSQL_PASSWORD: example_db_pass
volumes:
- ./db:/docker-entrypoint-initdb.d
Thank you in advance.
I'm trying to a selenium hub, chrome node, and firefox node, and my code that runs the test execution script in that order. I have the nodes depending on the hub and the code depending on both hubs. However, running docker-compose --build builds the code first and tries to run without starting the selenium components. I am unsure what I am doing wrong.
docker-compose.yml
version: '3'
services:
hub:
image: selenium/hub
networks:
robottestsnw: {}
ports:
- 4444:4444
chrome:
image: selenium/node-chrome
networks:
robottestsnw: {}
depends_on:
- hub
shm_size: '2g'
environment:
SCREEN_WIDTH: 1920
SCREEN_HEIGHT: 1080
HUB_HOST: hub
firefox:
image: selenium/node-firefox
networks:
robottestsnw: {}
depends_on:
- hub
shm_size: '2g'
environment:
HUB_PORT_4444_TCP_ADDR: hub
SCREEN_WIDTH: 1920
SCREEN_HEIGHT: 1080
HUB_HOST: hub
robottests:
build: .
networks:
robottestsnw: {}
depends_on:
- chrome
- firefox
networks:
robottestsnw:
driver: bridge
Dockerfile
# Dockerfile
# Base image
FROM sgrio/java-oracle
RUN apt-get update
RUN apt-get install -y maven
# Copy test project files to the image folder
COPY . /frontend-integration-tests
# Make the folder as a working directory
WORKDIR /frontend-integration-tests
# Install the test project libraries
RUN mvn package
CMD ["java", "-cp", "target/automated-testing 0.0.1-SNAPSHOT.jar", "automated-testing.service.App"]
docker-compose up
It starts services in dependency order, about docker-compose --build up don't sure. And maybe your port, network name are defined wrong:
hub:
image: selenium/hub
networks:
- robottestsnw
ports:
- 4444:4444