I'm working on building Docker images containing CK and its dependencies.
A snapshot of my Dockerfile
based on Ubuntu 16.04 is as follows:
FROM ubuntu:16.04
MAINTAINER Anton Lokhmotov
# Install standard packages.
RUN apt-get update && apt-get install -y \
python-all \
git
# Install the core Collective Knowledge (CK) module.
ENV CK_ROOT=$HOME/CK/ck CK_TOOLS=$HOME/CK_TOOLS PATH=$CK_ROOT/bin:$PATH
RUN mkdir -p $HOME/CK && git clone https://github.com/ctuning/ck.git $CK_ROOT
RUN mkdir -p $HOME/CK_TOOLS
RUN cd $CK_ROOT && python setup.py install && python -c "import ck.kernel as ck"
# Install other CK modules.
RUN ck pull repo:ck-web
# Listen on the standard CK port.
CK_PORT=3344
EXPOSE $CK_PORT
# Start the web service.
CMD ck start web --host=`hostname -i` --port=${CK_PORT}
To build an image named ctuning/ck-ubuntu-16.04
, run:
$ docker build -t ctuning/ck-ubuntu-16.04 ${DOCKERFILE_DIR}
where ${DOCKERFILE_DIR}
is the directory containing the above Dockerfile
(e.g. ${CK_DOCKER_DIR}/docker/ubuntu-16.04
).
The CK web service can be accessed at http://localhost:3344/
by running the image in a container as follows:
$ docker run --rm -it -p 3344:3344 ctuning/ck-ubuntu-16.04
For now we can only start server indefinitely
but we should add a proper start/stop/resume support at some point ...
Starting CK web service on 172.17.0.2:3344 ...
or at http://localhost:3355/
with a more elaborate command:
$ export WFE_PORT=3355 CK_PORT=3366
$ docker run --rm -it -p ${WFE_PORT}:${CK_PORT} --env CK_PORT=${CK_PORT} \
ctuning/ck-ubuntu-16.04
For now we can only start server indefinitely
but we should add a proper start/stop/resume support at some point ...
Starting CK web service on 172.17.0.2:3366 ...
That is, the CK web service is running inside the container with --host=
hostname -i`` and --port=${CK_PORT}
, and can be accessed at `http://localhost:${WFE_PORT}`. So far so good.
Now, suppose I want to access the CK web service running inside a Docker container on http://${WFE_HOST}:${WFE_PORT}
. I have port forwarding enabled from ${WFE_PORT}
to the ${WFE_HOST}
machine where the container is running. Here's what I have to do currently:
$ docker run --rm -it -p ${WFE_PORT}:${CK_PORT} --env CK_PORT=${CK_PORT} \
ctuning/ck-ubuntu-16.04 /bin/bash
root@cc8a1ff17ae9:/# ck setup kernel --wfe
=======================================================================
Loading current configuration ...
=======================================================================
*** Web front end control (through CK web server or third-party web server and CK php connector) ***
Current web front-end URL prefix: http://localhost:3344/web?
Current web front-end template: default
Enter new web front-end URL prefix (Enter to keep previous): http://<WFE_HOST>:<WFE_PORT>/web?
Enter new web front-end template (Enter to keep previous):
=======================================================================
Writing local configuration (directly) ...
Configuration successfully recorded to /root/CK/local/kernel/default/.cm/meta.json ...
root@cc8a1ff17ae9:/# ck start web --host=`hostname -i` --port=${CK_PORT} --use_wfe_url
For now we can only start server indefinitely
but we should add a proper start/stop/resume support at some point ...
Starting CK web service on 172.17.0.2:3366 ...
I have to explicitly type in the values of ${WFE_HOST}
and ${WFE_PORT}
into http://<WFE_HOST>:<WFE_PORT>/web?
, which is cumbersome, error-prone and not easily automate-able.
I propose to enable launching the CK web service as follows:
$ ck start web \
--host=`hostname -i` --port=${CK_PORT} \
--wfe_host=${WFE_HOST} --wfe_port=${WFE_PORT}
Then, the Dockerfile
file would look something like:
FROM ubuntu:16.04
MAINTAINER Anton Lokhmotov <[email protected]>
# Install standard packages.
RUN apt-get update && apt-get install -y \
python-all \
git
# Install the core Collective Knowledge (CK) module.
ENV CK_HOME=/root/CK \
CK_TOOLS=/root/CK_TOOLS \
CK_ROOT=${CK_HOME}/ck-core \
PATH=${CK_ROOT}/bin:${PATH}
RUN mkdir -p ${CK_HOME} && git clone https://github.com/ctuning/ck.git ${CK_ROOT}
RUN mkdir -p ${CK_TOOLS}
RUN cd ${CK_ROOT} && python setup.py install && python -c "import ck.kernel as ck"
# Install other CK modules.
RUN ck pull repo:ck-web
# Set the CK web service defaults.
ENV CK_PORT=3344 \
WFE_PORT=3344 \
WFE_HOST=localhost
# Listen on the CK port.
EXPOSE ${CK_PORT}
# Start the CK web service.
CMD ck start web \
--host=`hostname -i` --port=${CK_PORT} \
--wfe_host=${WFE_HOST} --wfe_port=${WFE_PORT}