Mittwoch, 21. August 2019

Docker Compose Webapps Port Forwarding

Multiple Webapps Inside Docker Compose Setup

  • Learn how to setup a custom network for your containers: container A talks to container B
  • Learn how to run multiple webapps inside Docker containers on different ports with Docker Compose
  • Create the network with $docker network create skynet
  • Run with $docker-compose up
  • Stop with $<Ctrl + C>
  • Clean up from time to time (beware, network will be deleted as well) with $docker system prune -a -f





Dienstag, 20. August 2019

Docker How To Map Ports To Tomcat Application Server

How to map ports to your Tomcat application server in Docker.
Example uses Tomcat 7.

Adapt to your tomcat directory if using another version.

In Dockerfile:

#start Tomcat and map Port 8080 to Container Port 8080
RUN sed -i 's/port="8080"/port="8080"/' /opt/apache/tomcat/conf/server.xml

URL: http://localhost:8080



Example 8081:

#start Tomcat and map Port 8080 to Container Port 8081
RUN sed -i 's/port="8080"/port="8081"/' /opt/apache/tomcat/conf/server.xml

URL: http://localhost:8081

Mittwoch, 14. August 2019

Docker - How to shrink large Docker Images.

Some images become very big - one reason being that multiple RUN commands will create a layer and keep the data there. No removal.

Example:

RUN unzip myfile.war  -d mynewdirectory/
RUN zip -r myfile.war mynewdirectory/
RUN mv myfile.war somedirectory

The myfile.war will be kept. It will not be deleted by the mv command.

Reason: Docker will create a layer for each RUN command.

Solution:

RUN unzip myfile.war  -d mynewdirectory/ &&\
    zip -r myfile.war mynewdirectory/ &&\
    mv myfile.war somedirectory

Keep everything in one layer by utilizing concatenation with '&&\'.

WARNING:
Docker is highly optimized and based on Checksums.
If everything is concatenated, building an image can take very long. 

Example: COPY or ADD will check wether a change in the underlying files or source code has been made and only execute if a change is detected.
Through concatenation, you reap Docker of the benefits regarding optimization (e.g. Checksums). No check. Everything is executed.

It is a good practice to keep this in mind when concatenating instrunctions.

Donnerstag, 1. August 2019

How to make Virtualbox available on Windows via localhost

Sometimes fate forces us to work with Windows.
Because Linux is so good, we get a VirtualBox to emulate it.

How can we access a webapplication via localhost:8080 from the Windows machine inside of a Webbrowser?

VirtualBox Manager -> VM-Tools -> Settings -> Network -> Port Forwarding

Name: http8080 
Protocol: TCP
HostIP: empty
Host-Port: 8080
Guest-IP: empty
Guest-Port: 8080


Name: ssh 
Protocol: TCP
HostIP: 127.0.0.1
Host-Port: 2222
Guest-IP: empty
Guest-Port: 22

NEW BLOG! http://cleancode.consulting/

Dear Reader, This Blog is closed and remains as an archive. Please find our new Blog at  http://cleancode.consulting/