Home > Net >  How am I able to use multiple operating system images within Docker?
How am I able to use multiple operating system images within Docker?

Time:04-14

I'm currently using Docker to deploy a development version of a web application. This is the docker-compose.yml file I wrote

version: '3'

services:

  nginx:
    build:
      context: ./docker/nginx
    ports:
      - "80:80"
    volumes:
      - .:/var/www/html/acme.com
      - ./docker/nginx/acme.com.conf:/etc/nginx/conf.d/acme.com.conf
    networks:
      - my_network

  php:
    build:
      context: ./docker/php
    ports:
        - "9000:9000"
    volumes:
      - .:/var/www/html/acme.com
    networks:
      - my_network

  database:
    build:
      context: ./docker/database
    volumes:
      - ./docker/database/acme.sql:/docker-entrypoint-initdb.d/acme.sql
      - ./docker/database/remote_access.sql:/docker-entrypoint-initdb.d/remote_access.sql
      - ./docker/database/custom.cnf:/etc/mysql/conf.d/custom.cnf
    ports:
        - "3306:3306"
    environment:
      MYSQL_DATABASE: ${db_database}
      MYSQL_ROOT_PASSWORD: ${db_password}
    networks:
      - my_network

networks:
  my_network:
    driver: bridge

Looking more closely at the different context files for nginx and mysql are as follows:

./docker/nginx/Dockerfile

FROM nginx:alpine

./docker/database/Dockerfile

FROM mariadb:latest

So it is evident that nginx image uses the alpine base image.

But what image is mariadb using? I went through the dockerhub website and followed the link to https://github.com/MariaDB/mariadb-docker/blob/db55d2702dfc0102364a29ab00334b6a02085ef9/10.7/Dockerfile

In this file, there is a reference to

FROM ubuntu:focal

Does this mean that my docker container is using the alpine linux base image as well as the ubuntu image? How does it work if I have multiple linux distributions in my container?

What should I do to fix this? Should I rather install mariadb using a FROM command into alpine linux and build my own docker image?

CodePudding user response:

Imagine your docker compose as a server farm. Each service (nginx, mariadb, ..) would be a physical server running an OS and its software. They are all connected via LAN within the same subnet. Each machine has its own IP address and there is a DNS and DHCP service running for giving the IPs and resolving names (service name = DNS-Alias). And there is a router blocking all connections from other subnets (= your host). Exceptions are configured by port mapping (=forwarding) ports: - 8000:8000.

So you can mix servers with all different OS variants of one type. This is due to the fact that docker is not a real virtual machine but more a VM light using the host OS resources to run the containers. So you can mix all kind of Linux distributions OR Windows versions. Every container uses the OS suiting it goals the best, e.g. Alpine for very small footprint and Ubuntu for much more comfort.

CodePudding user response:

You ask: Does this mean that my docker container is using the alpine linux base image as well as the ubuntu image?

No. Because they are different docker containers.

So, there's nothing to fix. Everything is fine.

But question: Why are you building all these images? Why not using the standard image?

  • Related