42

I have following question:

How to run docker with experimental features on (like image squashing docker build --squash=true... for reduce it size) on ubuntu 16.04 ?

Kamil Kiełczewski
  • 85,173
  • 29
  • 368
  • 345

6 Answers6

93

To turn on experimental docker functions create following file by:

sudo nano /etc/docker/daemon.json

and add below content to it

{ 
    "experimental": true 
} 

and save file (by CTRL+X and Enter ) and exit. In terminal type:

sudo service docker restart

To check that experimental funcions are ON, type in terminal:

docker version

And you should see Experimental: true

UPDATE

Instead of nano you can use this one-liner:

echo $'{\n    "experimental": true\n}' | sudo tee /etc/docker/daemon.json
Hans Ginzel
  • 8,192
  • 3
  • 24
  • 22
Kamil Kiełczewski
  • 85,173
  • 29
  • 368
  • 345
  • 3
    Note the limitations of that one-liner update: It's trying to 'append' however if you actually already have a config file, it will break the file format. – Mike Schroll Apr 23 '19 at 13:21
  • sudo sh -c 'echo "$(cat /etc/docker/daemon.json) {\"experimental\": true}" |jq -s add |sponge /etc/docker/daemon.json && service docker restart' – caduceus Sep 12 '19 at 09:03
  • 12
    fyi- to enable this for the client, the config file to create is `~/.docker/config.json` and the value is `"enabled"`, not `true` – Michael Haren Oct 22 '19 at 18:21
  • Not sure, but I think `sudo service docker restart` will shut down any docker containers running, just be careful – alan.elkin Nov 26 '21 at 16:07
18

I tried everything here on a Ubuntu 18.04 VM on my mac--nothing worked. All over the interwebs said the same thing, but the one thing that finally got experimental turned on was @Michael Haren's tiny answer:

fyi- to enable this for the client, the config file to create is ~/.docker/config.json and the value is "enabled", not true

which meant something like this for me:

$ mkdir ~/.docker
$ echo '{ "experimental": "enabled" }' > ~/.docker/config.json
$ sudo systemctl restart docker
$ docker version
  ...
  Experimental: true
  ...

This should be a top-level answer. So, credit to them (except sweet internet karma points for me...).

petemyron
  • 766
  • 5
  • 7
10

If you only want to run it temporarily / without modifying files, you can export DOCKER_CLI_EXPERIMENTAL=enabled. The below turns on experimental mode for your client.

$ docker version
 Experimental:      false
$ export DOCKER_CLI_EXPERIMENTAL=enabled
$ docker version
 Experimental:      true
HeroCC
  • 988
  • 15
  • 33
2

Posting this to help those who are running docker on macOS

You will need to enable experimental on two files, one is client while another is docker engine

I suggest open the file manually instead of direct echo into the file as that file might have some other configuration and you might not want to overwrite them accidentally

For client, visit ~/.docker/config.json, and add "experimental": "enabled" on top level config as below

{
  "experimental" : "enabled",
  "auths" : {
    "harbor.xxx.com" : {

    }
  },
  "credsStore" : "desktop"
}

For Docker Engine, visit ~/.docker/daemon.json and add "experimental": true on top level config as below

{
  "features": {
    "buildkit": true
  },
  "experimental": true,
  "builder": {
    "gc": {
      "defaultKeepStorage": "20GB",
      "enabled": true
    }
  }
}

Do note that the "value" of experimental is different between client and server.

Once done, restart the docker using command below

killall Docker && open /Applications/Docker.app

then verify the result

docker version
Isaac
  • 12,042
  • 16
  • 52
  • 116
2

I think you can solve this on Linux using the systemctl as described by https://stackoverflow.com/a/70460819/433814 on this SO. However, first you need to edit the correct files... Here's the way to set it up in a MacOS if you were looking for similar answers.

Docker run with Experiments MacOS

  • Just set the variable ENABLED=true or ENABLED=false and this script will automagically turn it on or off, writing to the file

NOTE: You MUST have jq installed to execute and update in-place.

ENABLED=true; \

CONFIG=~/.docker/config.json; DAEMON=~/.docker/daemon.json ; \

cat <<< $(jq --argjson V ${ENABLED} '.experimental = $V' ${DAEMON}) > ${DAEMON} ; \
cat <<< $(jq --arg V $(if [ "${ENABLED}" = "true" ]; then echo "enabled"; else echo "disabled"; fi) '.experimental = $V' ${CONFIG}) > ${CONFIG} ; \ 

cat ~/.docker/config.json ; \
cat ~/.docker/daemon.json

Output confirmation

  • This will be output automatically confirming
{
  "auths": {
    "https://index.docker.io/v1/": {},
    "registry.gitlab.com": {}
  },
  "credsStore": "desktop",
  "experimental": "enabled",
  "currentContext": "default"
}
{
  "builder": {
    "gc": {
      "defaultKeepStorage": "20GB",
      "enabled": true
    }
  },
  "experimental": true,
  "features": {
    "buildkit": true
  }
}

Restart Docker Engine in MacOS

  • Just run the following
killall Docker && open /Applications/Docker.app

References

Marcello DeSales
  • 21,361
  • 14
  • 77
  • 80
1
sudo sed -i 's/ExecStart=\/usr\/bin\/dockerd -H fd:\/\/ --containerd=\/run\/containerd\/containerd.sock/ExecStart=\/usr\/bin\/dockerd -H fd:\/\/ --containerd=\/run\/containerd\/containerd.sock --experimental/g' /lib/systemd/system/docker.service
sudo systemctl daemon-reload
sudo systemctl restart docker
Anafem
  • 11
  • 1
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 23 '21 at 10:59