# ansible2.4 can not run dockerd(binary) in backgroud

**URL:** <https://forum.ansible.com/t/ansible2-4-can-not-run-dockerd-binary-in-backgroud/25989>\
**Category:** Ansible Project\
**Created:** [November 10, 2017, 9:08am UTC](https://forum.ansible.com/t/ansible2-4-can-not-run-dockerd-binary-in-backgroud/25989 "2017-11-10T09:08:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![twinmegami\_arara](https://avatars.discourse-cdn.com/v4/letter/t/439d5e/32.png) [@twinmegami\_arara](https://forum.ansible.com/u/twinmegami_arara)\
**Post date:** [November 10, 2017, 9:08am UTC](https://forum.ansible.com/t/ansible2-4-can-not-run-dockerd-binary-in-backgroud/25989/1 "2017-11-10T09:08:03Z")

</div>

##### ANSIBLE VERSION

```auto
2.4.1.0

```

##### OS / ENVIRONMENT

centos 7 in vagrant

##### SUMMARY

# install docker script

```auto
function docker_install() {
echo "docker install"
if [${sysOS} == "Linux"]
then

if [! -f /tmp/install_docker_flag]; then

rm -f /var/run/docker.sock

tar zxvf ${DOCKER_ENGINE_DIR}/${DOCKER_FILE}.tar.gz
mv ${DOCKER_FILE}/* /usr/local/bin

tar zxvf ${DOCKER_ENGINE_DIR}/${DOCKER_COMPOSE_FILE}.tar.gz
mv ${DOCKER_COMPOSE_FILE}/* /usr/local/bin/docker-compose

# echo '{"insecure-registries":["'${PRIVATE_REGISTRY}'"]}' > /etc/docker/daemon.json
mkdir -p /etc/docker
echo '{"registry-mirrors": ["http://'${PRIVATE_REGISTRY}'"], "insecure-registries" : ["'${PRIVATE_REGISTRY}'"] }' > /etc/docker/daemon.json

rm -fr ${DOCKER_FILE}
rm -fr ${DOCKER_COMPOSE_FILE}

echo 'success' > /tmp/install_docker_flag
else
echo 'already installed docker'
fi

else
echo "this is "${sysOS}
exit 1
fi

}

```

This just copy dockerd binary to /usr/local/bin

# start docker

```auto
- name: start docker
shell: /usr/local/bin/dockerd >/dev/null 2>&1 &
# command: sh {{ start_docker_script }}

```

# logs

1. But script `docker load < ${DOCKER_IMAGES_DIR}/${packages['registry']}` in `TASK [registry : Install registry]` , complain docker not found.
2. After ansible failed, I enter that vm, confirmed dockerd was not running.
3. I also tried to start `dockerd ` by a script , nether work.
4. I enter vagrant and have confirmed all files copied successful .
5. In vagrant vm, directly run `/usr/local/bin/dockerd >/dev/null 2>&1 &` is working

```auto
TASK [common : Install docker] ********************************************************************************
changed: [host02]
changed: [host01]

TASK [common : start docker] **********************************************************************************
changed: [host02]
changed: [host01]

PLAY [registry] ***********************************************************************************************

TASK [Gathering Facts] ****************************************************************************************
ok: [host01]

TASK [registry : Install registry] ****************************************************************************
fatal: [host01]: FAILED! => {
"changed": true,
"cmd": [
"sh",
"/data/bidspy-yychen/dist/scripts/install_registry.sh"
],
"delta": "0:00:00.045283",
"end": "2017-11-10 03:28:33.555247",
"failed": true,
"rc": 125,
"start": "2017-11-10 03:28:33.509964"
}

STDOUT:

/data/bidspy-yychen/dist/scripts
/data/bidspy-yychen/dist

STDERR:

Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.
See 'docker run --help'.

MSG:

non-zero return code

```

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [November 10, 2017, 4:00pm UTC](https://forum.ansible.com/t/ansible2-4-can-not-run-dockerd-binary-in-backgroud/25989/2 "2017-11-10T16:00:32Z")

</div>

Your deamon doesn't start, but you're redirecting everything to  
/dev/null, which masks any issues.  
Try redirecting everything to a log file and examine that.

Dick

---

<div class="post-metadata">

**Author:** ![twinmegami\_arara](https://avatars.discourse-cdn.com/v4/letter/t/439d5e/32.png) [@twinmegami\_arara](https://forum.ansible.com/u/twinmegami_arara)\
**Post date:** [November 13, 2017, 5:34am UTC](https://forum.ansible.com/t/ansible2-4-can-not-run-dockerd-binary-in-backgroud/25989/3 "2017-11-13T05:34:48Z")

</div>

log only shows

```auto
time="2017-11-13T06:28:03.485879714+01:00" level=warning msg="could not change group /var/run/docker.sock to docker
: group docker not found"
time="2017-11-13T06:28:03.488257938+01:00" level=info msg="libcontainerd: new containerd process, pid: 8426"

```

I also tried install dockerd as service

```auto

- template:
src: templates/dockerd.service.j2
dest: /etc/systemd/system/dockerd.service
owner: root
mode: 0644

- systemd:
name: dockerd
state: started
enabled: True

```

But still same error , need restart dockerd

- systemd:  
name: dockerd  
state: restarted

before run command `docker run -d xxx`
