I want to mimic a centos7 server with phpfpm, nginx, mysql on Docker for Mac.
Currently I have this in my docker-compose.yml
, but, haven't stated anything about an OS anywhere.
version: '2'
services:
web:
build: .
image: nginx:latest
ports:
- "8080:80"
volumes:
- ./code:/code
- ./default.conf:/etc/nginx/conf.d/default.conf
networks:
- code-network
php:
image: php:fpm
volumes:
- ./code:/code
- ./log.conf:/usr/local/etc/php-fpm.d/zz-log.conf
networks:
- code-network
networks:
code-network:
driver: bridge
I think it is best to keep these services as separate containers, but, I presume they would all need to be different instances of CentOS, Right?
How would I go about setting this up, or, is there a better way to deal with this?
Many thanks,
Best Answer
If you absolutely want to use only centOS-based images, you may need to consider building your own.
In which case, all your Dockerfiles would need to start with:
An nginx container based on centos might be built with:
It does sound like you may want to read up on docker a little, though - and since you mention wanting to 'mimic a server that is running centOS', then it may be a virtual machine is a more suitable choice than docker.
Do take into account that docker containers do not need to have any OS 'in' them at all - it is entirely possible to build a container with a single binary (and this is actually somewhat common for programmes written in go, AFAIK). Containers are intended to be process-centric - that is, you run one programme, normally in the foreground, per container (so nginx, php-fpm). The 'OS' in a container is basically just a set of commands - the container 'OS' notably has no kernel of its own, but uses the host kernel instead. You 'install' CentOS so you can use CentOS tooling (and the same for your OS of choice) - but the resulting system is not necessarily the same thing as having a VM or physical host with CentOS (notably because the kernels may well be different, and have different features).