I use docker as a tool for daily job. Instead of installing node.js, I use docker images as short-living containers, to use tools like node and npm. I mount my local directory into the container, and then run it, and let the software from container do its job. I have many different local directories, each used with the same image/container, to manage a different project.
My question is simple: can this model be also used to work with OCaml and Opam?
So far, I have found the docker image ocaml/opam, but I haven’t figure out how to setup development environment in my local directory, that could be reused every time when the container is started and the directory is mounted inside the container.
Sure, that works fine; I do that all the time. You want to use the ocaml/opam2 images (documented here), and just volume mount your local directory into /home/opam/src. If you’re using Docker for Mac, then the uid mapping will be taken care of for you, and otherwise ensure that your local directory is uid 1000 to match the opam user in the containers.
docker run --rm -it --net host ocaml/opam2:ubuntu-18.04 opam depext -i conf-m4
# Detecting depexts using vars: arch=x86_64, os=linux, os-distribution=ubuntu, os-family=debian
# The following system packages are needed:
m4
The following command needs to be run through "sudo":
apt-get install -qq -yy m4
sudo: unable to send audit message: Unknown error -1
sudo: pam_open_session: System error
sudo: policy plugin failed session initialization
OS package installation failed
The problem is, the opam user is not root.
How can one become root in this image? (sudo bash doesn’t work).
I just tried running the same docker command and it seems to work for me:
docker run --rm -it --net host ocaml/opam2:ubuntu-18.04 opam depext -i conf-m4 ~
# Detecting depexts using vars: arch=x86_64, os=linux, os-distribution=ubuntu, os-family=debian
# The following system packages are needed:
m4
The following command needs to be run through "sudo":
apt-get install -qq -yy m4
sudo: unable to resolve host linuxkit-025000000001
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package libsigsegv2:amd64.
(Reading database ... 15258 files and directories currently installed.)
Preparing to unpack .../libsigsegv2_2.12-1_amd64.deb ...
Unpacking libsigsegv2:amd64 (2.12-1) ...
Selecting previously unselected package m4.
Preparing to unpack .../archives/m4_1.4.18-1_amd64.deb ...
Unpacking m4 (1.4.18-1) ...
Setting up libsigsegv2:amd64 (2.12-1) ...
Setting up m4 (1.4.18-1) ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...
# OS packages installation successful
# Now letting OPAM install the packages
The following actions will be performed:
- install conf-m4 1
<><> Gathering sources ><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
-> installed conf-m4.1
Done.
# Run eval $(opam env) to update the current shell environment
My environment:
$ uname -a
Darwin vostok.local 17.7.0 Darwin Kernel Version 17.7.0: Thu Jun 21 22:53:14 PDT 2018; root:xnu-4570.71.2~1/RELEASE_X86_64 x86_64
$ docker --version
Docker version 18.03.1-ce, build 9ee9f40
The point is not to build with root, since you don’t need it. There does appear to be some SELinux policy or something else as part of your Docker installation, so it doesn’t look like a standard one to me. Why do you need --net host, and what distribution are you running on? More information needed to debug.