Deploying Spring Boot App in Docker container without auto starting Tomcat - docker

I was under the impression that including the line
CMD ["catalina.sh", "run"]
to the Dockerfile would be what triggers the Tomcat server to start.
I've removed that line but it still starts the server on deployment. I basically want to add the catalina.sh run and include CATALINA_OPTS all in a Kubernetes deployment to handle this stuff, but Tomcat still auto starts up when I deploy to a container.

Docker image usually has an entry point or a command already.
If you create your custom image based on another image from a registry, which is a common case, you can override base image entry point by specifying the ENTRYPOINT or the CMD directive.
If you omit the entry point in your docker file, it will be inherited from the base image.
Consider reading Dockerfile: ENTRYPOINT vs CMD article to have a better understanding of how it works.

Related

Change javascript file inside running .net core docker container

Due to a number of circumstances beyond my control that I cannot change, the task arose to update the java script in the running container. A .net core site is running in the container. I have successfully changed the script in the wwwroot folder, but these changes are not available to clients. I did "docker restart cont_id" and "kill-HUV 1" inside the container, but it didn't help. Can I somehow update the script without stopping the container? Here is the docker file:
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2.4
COPY . /app
WORKDIR /app
ENV ASPNETCORE_URLS http://+:80
EXPOSE 80
CMD [ "dotnet", "ххх.WebUi.dll" ]
You need to docker build a new image, docker stop && docker rm the existing container, and docker run a new container on the new image. You can rebuild the image while the old container is still running, but there's no way to cause the existing container to somehow "switch" to a different image.
There are a number of options that can only be set when you initially build a container; not just the image to use (and the versions of language runtimes and support libraries embedded in that image) but also port mappings, environment variable settings, volume mounts, and others. Deleting and recreating a container in this way is extremely routine. Tools like Docker Compose will let you write the container's settings into a file, so it's straightforward to recreate a container when needed.

run uwsgi after official nginx container start?

I just write a customized container dockerfile including CMD["uwsgi", "--ini", "uwsgi.ini"] based on nginx official image
And I see there's a CMD["nginx", "-g", "daemon off"] in the end of Dockerfile of this nginx official image.
That should means starting nginx when container starts.
So my CMD["uwsgi", "--ini", "uwsgi.ini"] in my dockerfile will overridde it, thus the container will immediately exit.
How should I not override it and make both nginx and uwsgi work?
I'v googled a lot but none of those solutions are based on nginx official image.
Obviously I can run another container just for uwsgi and connect it to nginx container(i.e. the container runned by nginx offcial image), but I think it's troublesome and unnecessary.
the nginx offcial image here
You can use ENTRYPOINT or CMD to run multiple processes inside a container by feeding a shell script/wrapper. You should try to refrain from it since that isn't a best practice. Single container should be responsible for managing single process.
However there is a workaround by which you can manage multiple processes inside a container i.e by using a shell script wrapper or supervisor.
It's there in official docs -
https://docs.docker.com/config/containers/multi-service_container/
First, this is not docker philosophy to run 2 processes in one container.
This is a commonly accepted one : officialy, and through the community
So you'd rather build a stack, with both a nginx and your application.
Provided you really want or need to do this your way, you can pipe several command within the CMD instruction if you specify the command shell at first... but you can also use a script here.
Remember that the script will be executed from within your container, so think from a container POV, and not from a host one!

How can I change a docker image start

I have a SOLR image starting with a default configuration when I start my container.
I want to change the way SOLR starts in my container by referencing a different configuration file. Of course, I still want to use the original image I had from the beginning.
What is the best practice to do so?
If I use a docker file referencing my original image it will start it with the default value as no script has been modified.
I also thought about committing my new configuration file on my image, that works but that still does not change the starting script.
Can someone guide me on the best practice to do that?
Thanks in advance for your help.
Startup of a container is always controlled by ENTRYPOINT & CMD. In this case if you want to override it, you can create your own script & define it in the CMD & ENTRYPOINT defines a null environment to execute CMD but moreover, it overwrites your previous ENTRYPOINT in Dockerfile(You can provide a different ENTRYPOINT script as well). You can do it as below in Dockerfile -
FROM solr:latest
...................
...................
COPY your-data /container-data
ENTRYPOINT ["/usr/bin/env"]
CMD /run.sh
You can copy your data inside container using COPY & define operations to be performed in run.sh, run.sh is your own script which you want to get executed on container startup.

Dockerizing web app (WAR file)

I want to Containerize a web application which is a WAR file along with Postgres as database and Tomcat as Server.
What will be the procedure to do that?
I am using the following dockerfile:
FROM tomcat:8-jre8 MAINTAINER lpradel
RUN echo "export JAVA_OPTS=\"-Dapp.env=staging\"" > /usr/local/tomcat/bin/setenv.sh
COPY ./application.war /usr/local/tomcat/webapps/staging.war
CMD ["catalina.sh", "run"]
Write a dockerfile for each application.
E.g: Base a dockerfile on a tomcat server docker image, copy over your warfile and start the tomcat in the cmd part of the dockerfile.
For postgres you should be able to use an existing image.
Updated answer:
The dockerfile you are using is correct. This should prepare a tomcat image which has the web application you want. However you may want to connect that tomcat container with postgress container.
Easier way to connect multiple containers would be to use a docker-compose file. To use docker-compose, refer to docker-compose#build.
Original answer
You can mount your war file in tomcat container at /usr/local/tomcat/webapps/name_of_your_file.war inside container. This will enable the war file to be automatically deployed by tomcat container.
By the way, I am doing the similar process and using mysql database. Taking a look at the my deployment file might be helpful to you.

Docker. Does restart container means the same as restart process from CMD instruction?

I have a container with ubuntu and CMD instruction in Dockerfile is:
CMD ["java", "-jar", "/opt/jetty/start.jar"]
which is actually working fine.
But when I need to change configuration of my application and restart JETTY - I do restart container.
docker restart my_container_name
But this restart does not take into account and changes are not applied to the application.
I check the same not in docker - and restart JETTY - everything works.
What I am doing wrong?
Thanks
What exactly constitutes "change configuration of my application"? If doing that is editing configuration files and those are built into your container (as opposed to be accessed via mounted volumes), you'll need to go back to docker build and all subsequent steps before those changes will take effect in the running container.
you need to rebuild when your configuration (Dockerfile) is changed:
sudo docker build .

Resources