Going inside docker container in build step

Raheel Masood March 26, 2018

I am trying to use bitbucket pipeline as follows

 

image: ubuntu:16.04

pipelines:
default:
- step:
script:
- apt-get update
- apt-get install -y curl
- curl -L https://github.com/docker/compose/releases/download/1.18.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
- chmod +x /usr/local/bin/docker-compose
- docker network create docker_default
- docker-compose -f docker/production.yml up -d --build
- docker exec -i -d frontend_php bash
- cd /var/www
- composer install
services:
- docker

 

What i wanted to do is do docker-exec  and then do rest of my steps including composer install and unit testing inside the container.

 

Somehow I receive the following error.

 

bash: cd: /var/www: No such file or directory

 

I am not sure if this is trying to run the cd command inside my frontend_php container or the build container.

 

I have mounted the code to /var/www in my production.yml file as follows 

 

version: '2'
services:
frontend_php:
container_name: frontend_php
build: ./php-fpm
working_dir: /var/www
networks:
- docker_default
volumes:
- ../:/var/www
frontend_nginx:
container_name: frontend_nginx
build: ./nginx
working_dir: /var/www
networks:
- docker_default
volumes_from:
- frontend_php
ports:
- 8080:80

networks:
docker_default:
external: true

2 answers

0 votes
Charles Bilbo September 21, 2020

did you ever figure this out. ? 

0 votes
Zaher Ghaibeh April 17, 2018

If you want my advice install any php library using composer and then run `docker-compose up` as any command you run after `docker exec -i -d frontend_php bash` is executed within pipeline host  not within your docker image.

you can check https://hub.docker.com/r/zaherg/php-7.2-xdebug-alpine/ which will provide you with a ready to run php image that has composer already installed, so your pipeline will be something like:

 

image: zaherg/php-7.2-xdebug-alpine:latest

pipelines:
default:
- step:
script:
- composer install

- curl -L https://github.com/docker/compose/releases/download/1.18.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
- chmod +x /usr/local/bin/docker-compose
- docker network create docker_default
- docker-compose -f docker/production.yml up -d --build
services:
- docker

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events