Bat Man
Bat Man

Reputation: 499

A Dockerfile doesn't install RUN dependencies

docker-compose.yml

  version: '3.7'
  services:
    php:
      build:
        context: .
        dockerfile: Dockerfile
      image: php:7.3-rc-fpm
      container_name: php_7.3-rc-fpm
      volumes:
        - .:/var/www/app
      restart: unless-stopped
      working_dir: /var/www
      stdin_open: true
      tty: true

Dockerfile

FROM php:7.3-rc-fpm

RUN apt-get update && apt-get install -y \
  build-essential \
  mysql-client \
  locales \
  zip \
  vim \
  unzip \
  git \
  curl


# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

# Install extensions
RUN docker-php-ext-install pdo_mysql mbstring zip pcntl

# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

# Copy existing application directory permissions
COPY --chown=www:www . /var/www

# Change current user to www
USER www

Started containers with

docker-compose up -d

and when I execute

docker-compose exec php bash

followed by

mysql --version

result in

bash: mysql: command not found

the mysql-client is missing and the others RUNs installation as well...

Any idea what is going on?

....and stackoverflow need more details to approve my edit when I don't have any ............

Upvotes: 1

Views: 1340

Answers (2)

godot
godot

Reputation: 1570

image: php:7.3-rc-fpm should be dropped.

It tells docker-compose to build from the "php_7.3-rc-fpm" image and not from the image build with your Dockerfile (it's a question of precedence). So it's normal that nothing you ask to install in the Dockerfile is available...

I tested to be sure and indeed, if you drop this line, the commands docker-compose exec php bash followed by mysql --version gives you what you expected.

Upvotes: 2

grapes
grapes

Reputation: 8636

You are misusing container image name. In your docker-compose.yml you tell:

services:
    php:
      build:
        context: .
        dockerfile: Dockerfile
      image: php:7.3-rc-fpm

That you want to build your own image and name it php:7.3-rc-fpm! But this is not your image' name - it is the name of a well-known php docker container! And in your Dockerfile you inherits from it:

FROM php:7.3-rc-fpm

So, you are overwriting public image but your own. And I can only guess, what will be the new image like.. Solution - remove image from your docker-compose file. It is not the image to be used, it is the name you want to give your image after being built, upon used in conjunction with build properties.

Upvotes: 2

Related Questions