0

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,

  • 1
    I don't follow your question. It looks like you're making two separate containers, so what is all this about "instances of CentOS"? – Michael Hampton Mar 13 '17 at 23:17
  • Forgive my incompetence, quite new to Docker. I want to mimic a server that is running CentOS, with phpfpm & nginx. I have seen several examples where someone's setup contains a Dockerfile that installs centos & other services with yum. Yes building 2 containers, but, aren't these containers built with an OS? Or are they simply just the services? For example, I create a "volume" for a local file to a file in the container here: - ./default.conf:/etc/nginx/conf.d/default.conf but couldn't the path differ dependent on the server? – joe Mar 14 '17 at 11:10
2

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:

FROM centos

An nginx container based on centos might be built with:

FROM centos

RUN yum install -y epel-release 
RUN yum update -y
RUN yum install -y nginx

ENTRYPOINT ["/usr/sbin/nginx","-g","daemon off;"]

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).

|improve this answer|||||
1

The images that you are using in the example are based both in debian (nginx, php:fpm) and are official iamges.

If you really want to mimic the centos server, maybe the best idea is to build your own images as comment @iwaseatenbyagrue in the previous answer

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.