1

I'm trying to create my first dev environment based on docker.

My host is Windows 10 I need to create stack Ubuntu:14.04 + php in separate images.

Dockerfile for ubuntu: FROM ubuntu:14.04

Dockerfile for php: FROM php:5.6-fpm

Just that simple. W\o any additional parameters at that point.

docker-compose.yml:

version: '3.7'
services:
  os:
    build:
      context: .
      dockerfile: .docker/ubuntu/Dockerfile
    container_name: ubuntu
    tty: true
    links:
      - php
  php:
    build: ./.docker/php
    container_name: php

Then docker-compose up --build

result is:

Building os
Step 1/2 : FROM ubuntu:14.04
 ---> 971bb384a50a
Step 2/2 : LABEL maintainer="Andrey Kryukov"
 ---> Using cache
 ---> 3d71726444ee

Successfully built 3d71726444ee
Successfully tagged nnrservice_os:latest
Building php
Step 1/2 : FROM php:5.6-fpm
 ---> 8d3dc6499e61
Step 2/2 : LABEL maintainer="Andrey Kryukov"
 ---> Using cache
 ---> b6fc0c83131b

Successfully built b6fc0c83131b
Successfully tagged nnrservice_php:latest
Starting ubuntu ... done
Starting php    ... done
Attaching to ubuntu, php
php    | [24-Aug-2018 05:14:01] NOTICE: fpm is running, pid 1
php    | [24-Aug-2018 05:14:01] NOTICE: ready to handle connections

And then docker-compose exec os /bin/sh result is:

#

W\o any errors. So I expected that php will be available inside my console. But no!

# php -v
/bin/sh: 1: php: not found
#

What I am doing wrong? Or maybe I losing some important concept?

3
  • I suggest you can try docker exec -it your_docker_name bash after you run up your service (maybe docker-compose up -d) and try it again. your_docker_name is the name which shows in docker ps Commented Aug 24, 2018 at 5:28
  • nope. Similar result ( PS C:\github\NNRService> docker exec -it ubuntu bash root@4f244e85fe73:/# php -v bash: php: command not found root@4f244e85fe73:/# Commented Aug 24, 2018 at 5:48
  • 1
    That's a right result because you didn't install php in your Ubuntu mirror. Actually, os is useless. Each docker mirror are different services, there are coupled. you should run this command to php, it will be nice to change a name of this mirror Commented Aug 24, 2018 at 6:05

1 Answer 1

2
docker-compose exec os /bin/sh

You're connecting to the os container and trying to execute php, which is in the PHP container. Obviously, that will not work because the os container has only the base utils, not the PHP libraries and PHP-FPM application which is in the php container, as evident by

php    | [24-Aug-2018 05:14:01] NOTICE: fpm is running, pid 1
php    | [24-Aug-2018 05:14:01] NOTICE: ready to handle connection

Why do you need an OS container and a PHP container? That defeats the purpose. The php container will have a base OS + required applications/libraries for PHP. You don't need two, if you goal is to just run PHP

Sign up to request clarification or add additional context in comments.

4 Comments

My task is to make the most accurate copy of my production environment. With OS version and php version. And many othet things, but later. I'm at the very starting point of docker learning )
to reiterate, you don't need an OS container. You target the docker engine, not the OS. Compose and multi-containers makes sense when you want to have an application server, webserver, database server containers. If you haven't yet, please read an overview of Docker on their docs page. docs.docker.com/get-started
And yes, I'm trying to build webserver with specified versions of all its components. Spec version of Ubuntu, spec ver of php, mysql and so on. Thats why I'm trying to use multi-containers
what I am saying is you don't need Ubuntu because your php, mysql etc containers will have that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.