Building & Testing Docker containers

Build your local Dockerfile

## CD to our dockerfile repo
cd ./docker-images/

## build our dockerfile
docker build --force-rm -t local/default:magento2 .

## run the new docker container in our shell
docker run -t -i local/default:magento2 /bin/bash

Debugging a container

When your build throws an error it may look something like this

Step 12 : RUN npm install -g phantomjs-prebuilt
 ---> Running in dbfa1b087708
/bin/sh: 1: npm: not found
The command '/bin/sh -c npm install -g phantomjs-prebuilt' returned a non-zero code: 127

Run the following command to get the image ID from the container HEX

## run this to get the image ID
docker ps -a

CONTAINER ID        IMAGE                        COMMAND                  CREATED             STATUS                       PORTS               NAMES
dbfa1b087708        5c1b9dfae1a9                 "/bin/sh -c 'npm inst"   2 minutes ago       Exited (127) 2 minutes ago               

SSH into the container “5c1b9dfae1a9” to see what has gone wrong

docker run --rm -it 5c1b9dfae1a9 /bin/bash

Clearing all Docker images/containers

Tidying up

## all containers
docker rm $(docker ps -a -q)

## all images
docker rmi $(docker images -q) --force

 

Gareth
Buy Me A Coffee
back arrowBack to Index