Posts mit dem Label docker werden angezeigt. Alle Posts anzeigen
Posts mit dem Label docker werden angezeigt. Alle Posts anzeigen

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.

Mittwoch, 24. Juli 2019

Howto create Docker Network with Docker Compose - Communication between Services inside of a Container

Create your network named 'yournetwork':

$ docker network create -d bridge yournetwork

You have created your own network now.
Verify it by typing

$network inspect yournetwork:

In the docker-compose.yml:

networks:
  yournetwork: #TODO remove this hard-coded network reference
    external:
      name: ${NETWORK}

  yourservice:
  container_name: "your-container-name"
    image: your-image-name:${TAG:-latest} #will pull the latest                                                #tagged image of yours
    ports:
    - 8080:8080 #example localhost:8080
    net: ${NETWORK}

Start it with:

$ NETWORK=yournetwork docker-compose-up

Donnerstag, 18. Juli 2019

DOCKER - No Space Left on Device // How to clean Docker on Linux

Sometimes Docker will simply claim to much space. Time for a clean up ;)

docker system prune -a -f

Attention: if your network is not in the default, this command will eventually erase your subnet immediately.

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/