Question: We are trying to enable experimental features on the ubuntu-latest image on github workflows, since would like to use `squash` to reduce image size. However this is not possible as we get the following error:

> 
> /home/runner/work/\_temp/59d363d1-0231-4d54-bffe-1e3205bf6bf3.sh: line
>  3: /etc/docker/daemon.json: Permission denied
> 
> 
> 

for the following workflow:

```
- name: Build, tag, and push TOING image to Amazon ECR
  id: build-image
  env:
    ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
    ECR_REPOSITORY: TOING/TOING/TOING_REPO
    IMAGE_TAG: TOING_TEST
    DOCKER_CLI_EXPERIMENTAL: enabled
  run: |
    #build and push images
    sudo rm -rf /etc/docker/daemon.json
    sudo echo '{"experimental": true}' >> /etc/docker/daemon.json
    sudo systemctl restart docker
    docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f core/TOING/Dockerfile .
    docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
    echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"

```

We have verified that the daemon.json file is properly updated, and also used sudo for our commands, as shown.

We have also opened an [issue on github](https://github.com/actions/starter-workflows/issues/336) regarding this, but have no response so far. I would be greatful for any help.

**PS**: We have tried both "`experimental": true` and `"experimental": "enabled"`.

Answer: 
> 
> We have verified that the daemon.json file is properly updated
> 
> 
> 

It looks like it's *not* properly updated, based on your error message:

> 
> /home/runner/work/\_temp/59d363d1-0231-4d54-bffe-1e3205bf6bf3.sh: line
>  3: /etc/docker/daemon.json: Permission denied
> 
> 
> 

What's going on here? Well, the `sudo` command will run the given command as `root`. But you're doing a shell redirect, which is handled by the shell itself, not by `sudo`. In other words, you're redirecting *the output of sudo*.

If you want to write to a file *as root* then you'll need to actually [run a command that writes the file, and then run *that* using sudo](https://superuser.com/questions/136646/how-to-append-to-a-file-as-sudo). For example:

```
echo '{"experimental": true}' | sudo tee -a /etc/docker/daemon.json

```
This works best for me.

```sh
tmp=$(mktemp)
sudo jq '.+{experimental:true}' /etc/docker/daemon.json > "$tmp"
sudo mv "$tmp" /etc/docker/daemon.json
sudo systemctl restart docker.service

```