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 ?

6 Answers 6

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
4
  • 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. Commented Apr 23, 2019 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
    Commented Sep 12, 2019 at 9: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 Commented Oct 22, 2019 at 18:21
  • Not sure, but I think sudo service docker restart will shut down any docker containers running, just be careful
    – alan.elkin
    Commented Nov 26, 2021 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...).

3
  • 1
    This unfortunately did not work on Ubuntu 20.04, @Kamil's answer did however.
    – luv2learn
    Commented Sep 26, 2020 at 2:02
  • Note that the OP specified 16.04, so it may work in 16.04 or possibly was working at the time the answer was posted in 03/2020.
    – luv2learn
    Commented Sep 26, 2020 at 2:10
  • 1
    This is the top answer! Commented Nov 11, 2020 at 13:18
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
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
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

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
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.
    – Community Bot
    Commented Dec 23, 2021 at 10:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.