Laradock usage

Laradock usage

When building Laradock’s nginx image I met a prolbem like: group "www-data" in use . This is because the group www-data is already created in the default base image nginx:alpine. So I changed the Dockfile of nginx as below to fix the problem:

FROM nginx:alpine

LABEL maintainer="Mahmoud Zalt <[email protected]>"

COPY nginx.conf /etc/nginx/

# If you're in China, or you need to change sources, will be set CHANGE_SOURCE to true in .env.

ARG CHANGE_SOURCE=false
RUN if [ ${CHANGE_SOURCE} = true ]; then \
    # Change application source from dl-cdn.alpinelinux.org to aliyun source
    sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/' /etc/apk/repositories \
;fi

RUN apk update \
    && apk upgrade \
    && apk --update add logrotate \
    && apk add --no-cache openssl \
    && apk add --no-cache bash \
    && adduser -D -H -u 1000 -s /bin/bash www-data -G www-data

Note -G www-data is added.

The following is the frequently used commands when working with laradock. listed here as reference.

1. docker-compose up -d nginx mysql workspace  
   docker-compose up -d nginx mysql phpmyadmin redis workspace
2. docker-compose exec workspace bash  // connects to workspace container

docker exec -it {container-id} bash // connects to any container

docker-compose exec --user=laradock workspace bash 
//to have files created as your host’s user. 

3. Go to nginx/sites and create config files to point to different project directory when visiting different domains.

- change the default names *.conf:

4. Add the domains to the hosts files.
127.0.0.1  project-1.test
127.0.0.1  project-2.test
...

5. visit http://project-1.test

Due to frequent modification of nginx and other services, these following clean home commands are also useful:

Delete all containers using grep laradock_ on the names, see: Remove all containers based on docker image name.
docker ps -a | awk '{ print $1,$2 }' | grep laradock_ | awk '{print $1}' | xargs -I {} docker rm {}

Delete all images containing laradock.
docker images | awk '{print $1,$2,$3}' | grep laradock_ | awk '{print $3}' | xargs -I {} docker rmi {}

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.