Kaibin Lin
Kaibin Lin

Reputation: 61

Does a docker image build on MacOS can be deployed to another OS like Linux?

I just got started with docker. To my understanding, docker container runs a discrete process on the host machine and shares system resources of host machine too to that process, and as we know, codes building for Linux may not able to run on MacOS, and vice versa. My question is: can a docker image built on an OS platform can be deployed to another OS, like MacOS to Linux, or Ubuntu to CentOS?

If the question is NO, how come it only has one official mysql image on docker repositories, but not multiple like for Mac, for Ubuntu, for RHEL?

Upvotes: 5

Views: 7688

Answers (4)

Jeremy
Jeremy

Reputation: 1568

Short form - yes it can, but i think it will depend on the setup - notably user/group in - docker-compose file.

Recently i had some issues with work docker-compose files being setup without a user specified, these work ok when building on a mac as had an app user, but when run on my linux machine the user defaulted to root and thus the build was not successful. So it depends on the quality of the config.

Upvotes: 0

wstejka
wstejka

Reputation: 41

In fact, the docker built from any linux-based image can be run (w/o VM as an additional layer) on any linux distribution that has the same OS kernel. It means docker built from e.g. SuSE image can be then run on Fedora/Ubuntu/Debian/etc... w/o any restrictions.

Upvotes: 1

emory
emory

Reputation: 10891

Docker on mac works by creating a linux virtual machine. So a docker image built on Mac is in fact built on a linux virtual machine and can be freely exchanged with most other docker systems - including most docker on windows. There is a windows version of dockers that is not linux based. Those images are not interchangeable.

Upvotes: 7

Mike
Mike

Reputation: 5142

Docker images are platform agnostic. The first thing a Dockerfile declares is what base image it pulls from, and that should determine the operating system under which the containers will run.

Using the MySQL 8 Dockerfile as an example:

https://github.com/docker-library/mysql/blob/223f0be1213bbd8647b841243a3114e8b34022f4/8.0/Dockerfile

FROM debian:stretch-slim

This means the image, and thus any containers started from it, will be based on Debian Linux...even if the host machine is MacOS.

Upvotes: -1

Related Questions