This step assembles a Dockerfile in order to develop a Phoenix web server. It lists the Dockerfile and then explains key lines. You will probably need to make some adjustments for your own use, so check the explanations.
FROM elixir:1.12-alpine LABEL maintainer="me_myself_i@work" LABEL version_date="2021-05-20" RUN apk add --no-cache --update \ git \ inotify-tools \ libpq postgresql-client \ nodejs npm yarn ENV USER="devuser" UID="1000" GID="1000" RUN addgroup -g $GID -S $USER && \ adduser -h /apps -g "" -G $USER -S -D -u $UID "$USER" USER $UID:$GID ENV PATH="/usr/local/lib/elixir/bin:/usr/local/lib/erlang/bin:$PATH" ENV PATH="/apps/.cache/rebar3/bin:$PATH" VOLUME /apps WORKDIR /apps EXPOSE 4000/tcp CMD sleep 50000
- Note this means use of the apk package manager for Alpine Linux rather than the apt utility used with Debian and Ubuntu. There is a full searchable library of packages available for Alpine Linux.
- By the time you read this, later editions may be available so adjust as necessary.
RUN apk add --no-cache --update \ git \ inotify-tools \ libpq postgresql-client \ nodejs npm yarn
Packages as follows:
inotify-tools adds into the container kernel so that changes to files can be detected by a running program within the container.
libpq is the shared object/ DLL for access to PostgreSQL.
postgresql-client adds in the PostgreSQL command line tools such as psql. This is not strictly needed and adds ~9MB to the image, but it is convenient to have on hand.
ENV USER="devuser" UID="1000" GID="1000"
Set some environment variables for use in setting up a user account for you as developer.
Matching the UID & GID between your host user account and the developer account in the image is key to using IDE's and other tools. You MUST use your own UID and GID here!
RUN addgroup -g $GID -S $USER && \ RUN adduser -h /apps -g "" -G $USER -S -D -u $UID "$USER"
These lines add a new group and a new user within that group.
- The remaining few lines are completed as the devuser. So signing in as devuser will have the $PATH, and start in the WORKDIR that you would expect.
ENV PATH="/usr/local/lib/elixir/bin:/usr/local/lib/erlang/bin:$PATH" ENV PATH="/apps/.cache/rebar3/bin:$PATH"
- Adds Elixir and Erlang into the $PATH.
VOLUME /apps WORKDIR /apps
The /apps/ folder within the container will be the $HOME folder of the devuser account.
The same folder will also be mapped as a volume to the ./myp_dev/source/ folder of the host user account (configured via the docker-compose.yml).
- This allows the default Phoenix web server port to be mapped to a known port number of the host machine. Precisely which port number is configured in the docker-compose.yml.
CMD sleep 50000
- Once a container runs, it wants to run to completion and then shutdown in an orderly fashion. We need it to hang around so we can attach a console and carry out our development work!
- An equivalent Dockerfile based on Debian or Ubuntu can readily be put together. Note however that the image will be near to twice the size(!).
- The inotify-tools capability will pick up changes originating inside the container, but may not notice changes originating outside the container (e.g. your IDE). It does however need to be present as Phoenix squeals if it isn't.