Skip to content

Commit 43256c1

Browse files
committed
Bind mount working directory into docker containers
1 parent 5914be5 commit 43256c1

File tree

9 files changed

+25
-57
lines changed

9 files changed

+25
-57
lines changed

docker/minimal-py2/Dockerfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,16 @@ RUN useradd -m -s /bin/bash -G sudo fidimag && \
4949
echo "fidimag ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
5050
RUN chown -R fidimag $FIDIMAG_HOME
5151

52+
# For bind mounts from host
53+
RUN mkdir /io
54+
RUN chown -R fidimag /io
55+
5256
USER fidimag
5357
RUN touch $FIDIMAG_HOME/.sudo_as_admin_successful
5458

5559
# Print something nice on entry.
5660
#COPY WELCOME $FIDIMAG_HOME/WELCOME
5761

5862

59-
60-
WORKDIR $FIDIMAG_HOME
63+
WORKDIR /io
6164
CMD ["/bin/bash","-i"]

docker/minimal-py2/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build:
44

55
# to run new image
66
run: build
7-
docker run -ti fidimag/minimal-py2
7+
docker run -v `pwd`:/io -ti fidimag/minimal-py2
88
# try 'ipython' and then 'import fidimag'
99

1010
# to push the new docker image to dockerhub (need to login first)

docker/minimal-py2/Readme.md

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,32 +21,10 @@ To use it, you can try this:
2121
This command should show a bash prompt inside the docker container:
2222

2323
<pre>
24-
bin:docker fangohr$ docker run -ti fidimag/minimal-py2
25-
fidimag@38fdd2a0feb4:~$
24+
bin:docker fangohr$ docker run -v `pwd`:/io -ti fidimag/minimal-py2
25+
fidimag@38fdd2a0feb4:/io$
2626
</pre>
2727

28-
One way to test the installation is to run the unit tests:
29-
30-
<pre>
31-
fidimag@38fdd2a0feb4:~$ cd fidimag/tests/
32-
fidimag@38fdd2a0feb4:~/fidimag/tests$ py.test -v
33-
========== test session starts =======================
34-
platform linux2 -- Python 2.7.6 -- pytest-2.5.1 -- /usr/bin/python
35-
collected 63 items
36-
37-
field_test.py:7: test_initialise_scalar PASSED
38-
field_test.py:13: test_initialise_vector PASSED
39-
test_2dpbc_cube.py:10: test_compute_field PASSED
40-
test_anis.py:7: test_anis PASSED
41-
.
42-
.
43-
.
44-
</pre>
45-
46-
## Shortcomings
47-
48-
- need to share directory between host and container (MOUNT or VOLUME)
49-
5028
## Creating the docker container
5129

5230
The `Makefile` in this directory shows the relevant targets (build, login, push)

docker/minimal-py3/Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ RUN useradd -m -s /bin/bash -G sudo fidimag && \
5050
echo "fidimag ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
5151
RUN chown -R fidimag $FIDIMAG_HOME
5252

53+
# For bind mounts from host
54+
RUN mkdir /io
55+
RUN chown -R fidimag /io
56+
5357
USER fidimag
5458
RUN touch $FIDIMAG_HOME/.sudo_as_admin_successful
5559

docker/minimal-py3/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build:
44

55
# to run new image
66
run: build
7-
docker run -ti fidimag/minimal-py3
7+
docker run -v `pwd`:/io -ti fidimag/minimal-py3
88
# try 'ipython3' and then 'import fidimag'
99

1010
# to push the new docker image to dockerhub (need to login first)

docker/minimal-py3/Readme.md

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,32 +21,10 @@ To use it, you can try this:
2121
This command should show a bash prompt inside the docker container:
2222

2323
<pre>
24-
bin:docker fangohr$ docker run -ti fidimag/minimal-py3
25-
fidimag@38fdd2a0feb4:~$
24+
bin:docker fangohr$ docker run -v `pwd`:/io -ti fidimag/minimal-py3
25+
fidimag@38fdd2a0feb4:/io$
2626
</pre>
2727

28-
One way to test the installation is to run the unit tests:
29-
30-
<pre>
31-
fidimag@38fdd2a0feb4:~$ cd fidimag/tests/
32-
fidimag@38fdd2a0feb4:~/fidimag/tests$ py.test-3 -v
33-
========== test session starts =======================
34-
platform linux2 -- Python 3.4.3 -- pytest-2.5.1 -- /usr/bin/python3
35-
collected 63 items
36-
37-
field_test.py:7: test_initialise_scalar PASSED
38-
field_test.py:13: test_initialise_vector PASSED
39-
test_2dpbc_cube.py:10: test_compute_field PASSED
40-
test_anis.py:7: test_anis PASSED
41-
.
42-
.
43-
.
44-
</pre>
45-
46-
## Shortcomings
47-
48-
- need to share directory between host and container (MOUNT or VOLUME)
49-
5028
## Creating the docker container
5129

5230
The `Makefile` in this directory shows the relevant targets (build, login, push)

docker/notebook/Dockerfile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,10 @@ RUN conda install --quiet --yes icu
2828
RUN conda install --quiet --yes pytest
2929
RUN py.test -v
3030

31+
# /io will be mounted from the host system
32+
USER root
33+
RUN mkdir /io
34+
RUN chown -R $NB_USER /io
35+
USER $NB_USER
3136

32-
WORKDIR $HOME/work
37+
WORKDIR /io

docker/notebook/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ build:
33
time docker build -t fidimag/notebook:latest .
44

55
# to run new image
6-
run:
7-
docker run -ti fidimag/notebook bash
6+
run: build
7+
docker run -v `pwd`:/io -d -p 30008:8888 fidimag/notebook
88

99
# to push the new docker image to dockerhub (need to login first)
1010
push: build

docker/notebook/Readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ To use it, you can try this:
1616

1717
3. Start the container using
1818

19-
docker run -d -p 30008:8888 fidimag/notebook
19+
docker run -v `pwd`:/io -d -p 30008:8888 fidimag/notebook
2020

2121
This will start a notebook server. You can see it in your browser at
2222
http://localhost:30008/ on Linux, or http://192.168.99.100:30008/ on Mac (you may
2323
need to change this IP address if your docker VM is at a different address).
2424

2525
To run a shell instead of the notebook server, run:
2626

27-
docker run -ti fidimag/notebook bash
27+
docker run -v `pwd`:/io -ti fidimag/notebook bash
2828

2929
## Shortcomings
3030

0 commit comments

Comments
 (0)