Running a Spring Boot app from Docker is not working - linux

I have a rather strange problem. I am trying to run a Spring Boot app via docker. So here are my steps.
1) I am creating a Dockerfile.
FROM centos
RUN yum install -y java
VOLUME /tmp
ADD /spring-boot-web-0.0.1-SNAPSHOT.jar myapp.jar
RUN sh -c 'touch /myapp.jar'
ENTRYPOINT [“java","-Djava.security.egd=file:/dev/./urandom","-
jar","/myapp.jar"]
In this file I am installing java. I am also using the jar file of the app called spring-boot-web-0.0.1-SNAPSHOT.jar
2) The next step is to build an image. So I am typing
tmp theodosiostziomakas$ docker build -t spring-boot-docker .
So the image was built correctly.
3) Now I am running that image to generate a container. So
docker run -d -p 8080:8080 spring-boot-docker
You can see that a container is generated. But when I type
$ docker ps
the container_id is not visible and when I type localhost:8080 in the browser the app is not running at all. Why is this happening? Any ideas? How to fix it?

If the posted Dockerfile the file you are using then there is a wrong quote sign just before java:
FROM centos
RUN yum install -y java
VOLUME /tmp
ADD /spring-boot-web-0.0.1-SNAPSHOT.jar myapp.jar
RUN sh -c 'touch /myapp.jar'
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/myapp.jar"]

Related

Nextcloud docker install with SSH access enabled

I’m trying to install SSH (and enable the service) on top of my Nextcloud installation in Docker, and have it work on reboot. Having run through many Dockerfile, docker-compose combinations I can’t seem to get this to work. Ive tried using entrypoint.sh scripts with Dockerfile, but it wants a CMD at the end and then it doesn’t execute the “normal” nextcloud start up.
entrypoint.sh:
#!/bin/sh
# Start the ssh server
service ssh start
# Execute the CMD
exec "$#"
Dockerfile:
FROM nextcloud:latest
RUN apt update -y && apt-get install ssh -y
RUN apt-get install python3 -y && apt-get install sudo -y
RUN echo 'ansible ALL=(ALL:ALL) NOPASSWD:ALL' >> /etc/sudoers
RUN useradd -m ansible -s /bin/bash
RUN sudo -u ansible mkdir /home/ansible/.ssh
RUN mkdir -p /var/run/sshd
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
CMD ["/usr/sbin/sshd", "-D"]
Any help would be much appreciated. Thank you
In general I'd say - break the problem you're having down into smaller parts - it'll help isolate the source of the problem.
Here's how I'd approach the reported issue.
First - replace (in your Dockerfile)
apt-get install -y ssh
with the recommended
apt install -y openssh-server
Then - test just the required parts of your Dockerfile addressing the issue - simplify it just to the following:
FROM nextcloud:latest
RUN apt update
RUN apt install -y openssh-server
Then build a test image using this Dockerfile via the command
docker build . -t test_nextcloud
This will build the image - giving it the name (tag) of test_nextcloud.
Then run a container from this newly built image via the docker run command
docker run -p 8080:80 -d --name nextcloud test_nextcloud
This will run the container on port 8080 in detatched mode, and give the assicated container the name of nextcloud.
Then - with the container running - you should be able to enter into it using the following command
docker container exec -u 0 -it nextcloud bash
as root.
Now that you are in, you should be able to startup the ssh server via the command
service ssh start
Having followed a set of steps like this to confirm that you can indeed startup an ssh server in the nextcloud container, begin adding back in your additional logic (begining with the original Dockerfile).

i created nodered application in docker , i tried rebuild docker because i need using other cli tools. e,g:aws cli

i need deploy to fargate, but nodered rebuild will follow hostname to create flow.json, this make me so hard to load old config to new nodered.
But now, if using docker run -h is work,but in fargate dose not work, how can i do?
Of course, release nodered docker version is solved this problem,but i don’t know how to call cli tools,if base on node-red, how can i install aws-cli2 and call it in nodered dashboard?
FROM nodered/node-red:latest
#USER root
RUN curl https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip -o awscliv2.zip
RUN unzip awscliv2.zip
RUN ./aws/install
CMD ["node-red"]
The correct Dockerfile would be:
FROM nodered/node-red:latest
USER root
RUN curl https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip -o awscliv2.zip
RUN unzip awscliv2.zip
RUN ./aws/install
RUN rm -rf ./aws
USER node-red
But the problem is that the image is based on Alpine Linux which uses the musl standard libraries instead of glibc. And the AWS tools will not work with this runtime.
The easiest solution will be to use the Debian based build that I mentioned in the first comment. The docker file for that can be found here, follow the instructions there to use the docker-debian.sh which will create an image called
testing:node-red-build which you can then use as the base for the Dockerfile I showed earlier:
FROM testing:node-red-build
USER root
RUN curl https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip -o awscliv2.zip
RUN unzip awscliv2.zip
RUN ./aws/install
RUN rm -rf ./aws
USER node-red

Run sshd in Docker container

I found this Dockerfile sample here:
// version 1
FROM ubuntu:latest
RUN apt update && apt install ssh -y
RUN service ssh start
CMD ["/usr/sbin/sshd","-D"]
When I build and run this Dockerfile, it runs an SSH server in the foreground, which is great.
If I use the following Dockerfile though:
// version 2
FROM ubuntu:latest
RUN apt update && apt install ssh -y
RUN service ssh start
# CMD ["/usr/sbin/sshd","-D"] // without this line
And then run the container:
~$ docker run -p 2222:22 -it ssh_server
And try to connect to it from another terminal, it doesn't work. Seemingly this call to sshd is necessary. On the other hand, If I just install SSH in the Dockerfile:
// version 3
FROM ubuntu:latest
RUN apt-get update && apt-get install -y ssh
And run the container like this:
~$ docker run -p 2222:22 -it ssh:test
~$ service ssh start
* Starting OpenBSD Secure Shell server sshd
Now I'm able to connect to the container. So I wonder: If the line RUN ssh service start
in version 1 is necessary, why isn't necessary for version 3?
To add more to the confusion, if I build and run version 4:
// version 4
FROM ubuntu:latest
RUN apt update && apt install ssh -y
#RUN service ssh start // without this line
CMD ["/usr/sbin/sshd","-D"]
It also doesn't work either.
Can someone please explain those behaviours? What is the relation between service ssh start and /usr/sbin/sshd?
OK everything is clear now:
Basically running the /usr/sbin/sshd is what runs the ssh server. The reason it didn't work out on it's own (version 4) is because the script that runs when you run service ssh start - which is the script /etc/init.d/ssh - creates a directory /run/sshd which is required for the run of sshd.
This script also calls the executable /usr/sbin/sshd, but since this is run as part of the build, it didn't sustain beyond the temporary container that the layer was made of. W
What did sustain is the /run/sshd directory! That's why when we run /usr/sbin/sshd as the CMD it works!
Thanks all!
To build on #YoavKlein's answer, service ssh start can take arguments which are passed to sshd, so rather than
# Incidentally creates /run/sshd
RUN service ssh start
# Run the service in the foreground when starting the container
CMD ["/usr/sbin/sshd", "-D"]
you can just do
# Run the service in the foreground when starting the container
CMD ["service", "ssh", "start", "-D"]
which will start the SSH server through service, but run it in the foreground, avoiding having to have a separate RUN to do first time setup.
I have taken the idea from #mark-raymond :)
Following docker run command with the -D flag worked for me!:
docker run -itd -p 2222:22 <dockerImageName:Tag> /usr/sbin/sshd -D

sudo: docker-compose: command not found

I am trying to run docker-compose using sudo.
I have both docker and docker-compose installed on Ubuntu 16.01.
Due to an error while trying to download compose using curl, I ended up installing it using pip.
Docker version 1.12.0, build 8eab29e
docker-compose version 1.8.0, build 94f7016
Yet, when I try to run docker-compose with sudo I get the following (using sudo with docker is fine)
sudo: docker-compose: command not found
I suppose there are differing definitions of what 'installed' means. I have been using docker-compose on the same computer that claims it is not installed.
$ dpkg -s docker-compose
dpkg-query: package 'docker-compose' is not installed and no information is available
Use dpkg --info (= dpkg-deb --info) to examine archive files,
and dpkg --contents (= dpkg-deb --contents) to list their contents.
$ whereis docker-compose
docker-compose: /home/user/.local/bin/docker-compose
$ pip show --files docker-compose
---
Metadata-Version: 2.0
Name: docker-compose
Version: 1.8.0
Summary: Multi-container orchestration for Docker
Home-page: https://www.docker.com/
Author: Docker, Inc.
Author-email: UNKNOWN
Installer: pip
License: Apache License 2.0
Location: /home/anton/.local/lib/python2.7/site-packages
Requires: six, jsonschema, enum34, cached-property, websocket-client, docker-py, requests, docopt, dockerpty, PyYAML, texttable
Classifiers:
Development Status :: 5 - Production/Stable
Environment :: Console
Intended Audience :: Developers
License :: OSI Approved :: Apache Software License
Programming Language :: Python :: 2
Programming Language :: Python :: 2.7
Programming Language :: Python :: 3
Programming Language :: Python :: 3.4
Files:
../../../bin/docker-compose
compose/GITSHA
compose/__init__.py
compose/__init__.pyc
compose/__main__.py
compose/__main__.pyc
compose/bundle.py
compose/bundle.pyc
compose/cli/__init__.py
compose/cli/__init__.pyc
compose/cli/colors.py
compose/cli/colors.pyc
compose/cli/command.py
compose/cli/command.pyc
compose/cli/docker_client.py
compose/cli/docker_client.pyc
compose/cli/docopt_command.py
compose/cli/docopt_command.pyc
compose/cli/errors.py
compose/cli/errors.pyc
compose/cli/formatter.py
compose/cli/formatter.pyc
compose/cli/log_printer.py
compose/cli/log_printer.pyc
compose/cli/main.py
compose/cli/main.pyc
compose/cli/signals.py
compose/cli/signals.pyc
compose/cli/utils.py
compose/cli/utils.pyc
compose/cli/verbose_proxy.py
compose/cli/verbose_proxy.pyc
compose/config/__init__.py
compose/config/__init__.pyc
compose/config/config.py
compose/config/config.pyc
compose/config/config_schema_v1.json
compose/config/config_schema_v2.0.json
compose/config/environment.py
compose/config/environment.pyc
compose/config/errors.py
compose/config/errors.pyc
compose/config/interpolation.py
compose/config/interpolation.pyc
compose/config/serialize.py
compose/config/serialize.pyc
compose/config/sort_services.py
compose/config/sort_services.pyc
compose/config/types.py
compose/config/types.pyc
compose/config/validation.py
compose/config/validation.pyc
compose/const.py
compose/const.pyc
compose/container.py
compose/container.pyc
compose/errors.py
compose/errors.pyc
compose/network.py
compose/network.pyc
compose/parallel.py
compose/parallel.pyc
compose/progress_stream.py
compose/progress_stream.pyc
compose/project.py
compose/project.pyc
compose/service.py
compose/service.pyc
compose/state.py
compose/state.pyc
compose/utils.py
compose/utils.pyc
compose/volume.py
compose/volume.pyc
docker_compose-1.8.0.dist-info/DESCRIPTION.rst
docker_compose-1.8.0.dist-info/INSTALLER
docker_compose-1.8.0.dist-info/METADATA
docker_compose-1.8.0.dist-info/RECORD
docker_compose-1.8.0.dist-info/WHEEL
docker_compose-1.8.0.dist-info/entry_points.txt
docker_compose-1.8.0.dist-info/metadata.json
docker_compose-1.8.0.dist-info/pbr.json
docker_compose-1.8.0.dist-info/top_level.txt
Entry-points:
[console_scripts]
docker-compose=compose.cli.main:main
I have tried the following - but still get the same error:
$ chmod +x /home/username/.local/bin/docker-compose
$ chmod +x /home/username/.local/lib/python2.7/site-packages
On Ubuntu 16.04
Here's how I fixed this issue: Refer Docker Compose documentation
sudo curl -L https://github.com/docker/compose/releases/download/1.21.0/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
After you do the curl command , it'll put docker-compose into the
/usr/local/bin
which is not on the PATH.
To fix it, create a symbolic link:
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
And now if you do:
docker-compose --version
You'll see that docker-compose is now on the PATH
The output of dpkg -s ... demonstrates that docker-compose is not installed from a package. Without more information from you there are at least two possibilities:
docker-compose simply isn't installed at all, and you need to install it.
The solution here is simple: install docker-compose.
docker-compose is installed in your $HOME directory (or other location not on root's $PATH).
There are several solution in this case. The easiest is probably to replace:
sudo docker-compose ...
With:
sudo `which docker-compose` ...
This will call sudo with the full path to docker-compose.
You could alternatively install docker-compose into a system-wide directory, such as /usr/local/bin.
If you have tried installing via the official docker-compose v1 page, where you need to download the binary using curl:
sudo curl -L https://github.com/docker/compose/releases/download/1.29.2/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
Then do not forget to add executable flag to the binary:
sudo chmod +x /usr/local/bin/docker-compose
If docker-compose is installed using python-pip
sudo apt-get -y install python-pip
sudo pip install docker-compose
try using pip show --files docker-compose to see where it is installed.
If docker-compose is installed in user path, then try:
sudo "PATH=$PATH" docker-compose
As I see from your updated post, docker-compose is installed in user path /home/user/.local/bin and if this path is not in your local path $PATH, then try:
sudo "PATH=$PATH:/home/user/.local/bin" docker-compose
I have same issue , i solved issue :
Following installs Docker Compose v1:
step-1 : download docker-compose using following command.
1. sudo su
2. sudo curl -L https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
Step-2 : Run command
chmod +x /usr/local/bin/docker-compose
Step-3 : Check docker-compose version
docker-compose --version
I will leave this here as a possible fix, worked for me at least and might help others. Pretty sure this would be a linux only fix.
I decided to not go with the pip install and go with the github version (option one on the installation guide).
Instead of placing the copied docker-compose directory into /usr/local/bin/docker-compose from the curl/github command, I went with /usr/bin/docker-compose which is the location of Docker itself and will force the program to run in root. So it works in root and sudo but now won't work without sudo so the opposite effect which is what you want to run it as a user anyways.
If docker-compose is installed for your user but not installed for root user and if you need to run it only once and forget about it afterwords perform the next actions:
Find out path to docker-compose:
which docker-compose
Run the command specifying full path to docker-compose from the previous command, eg:
sudo /home/your-user/your-path-to-compose/docker-compose up
On Ubuntu just run
sudo apt install docker-compose
This worked on Ubuntu 22*
You might be using a deprecated code. Try writing docker compose instead of docker-compose.
Simple, just reinstall the docker-compose. It will fix the issue.
sudo apt install docker-compose
There are too many pending edits on Stack Overflow, so I'm submitting a new answer that supplements earlier answers.
I propose the answer is syntax: docker compose vs docker-compose depending on how you have it installed, which is the same proposed answer by ibrahim shazly on Sep 27, 2022 and Gaurav Kumar Verma on Sep 29, 2022.
Here is an explanation. I followed https://docs.docker.com/engine/install/ubuntu/#install-docker-engine to install Docker on Ubuntu 22 LTS. Then, I attempted to run docker compose like so:
$ docker-compose up -d myserver
Command 'docker-compose' not found, but can be installed with:
...
As Gaurav Kumar Verma points out, https://docs.docker.com/compose/install/other/ has a disclaimer:
Note that Compose standalone uses the -compose syntax instead of the current standard syntax compose.
For example type docker-compose up when using Compose standalone, instead of docker compose up.
Thus, I ran:
$ docker compose up -d myserver
And it ran successfully.
Or, just add your binary path into the PATH. At the end of the bashrc:
...
export PATH=$PATH:/home/user/.local/bin/
save the file and run:
source .bashrc
and the command will work.
docker-compose is not installed. Please try to install it first from their official documentation
Whenever this type of error occurs please try to verify the installation of the apps by typing which command_name it will search for the executables and show you the location.
Had to delete a large log file then restart docker-compose for the space to clear up.
I used a script shell that cron runs once a day:
rm /var/log/cron/log_prodTEST.log
cd /opt/test/metrics
/usr/local/bin/docker-compose up --build --force-recreate -d -T
Apperntly by using the full path to docker-compose, I could use it inside the corn shell
you might try run the code by using docker compose instead of docker-compose
if it work you might want to check this link her
https://docs.docker.com/compose/install/other/
sudo curl -L "https://github.com/docker/compose/releases/download/v2.12.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo mv /usr/local/bin/docker-compose /usr/bin/docker-compose
sudo chmod +x /usr/bin/docker-compose

Docker can't connect to docker daemon

After I update my Docker version to 0.8.0, I get an error message while entering sudo docker version:
Client version: 0.8.0
Go version (client): go1.2
Git commit (client): cc3a8c8
2014/02/19 12:54:16 Can't connect to docker daemon. Is 'docker -d' running on this host?
And I've followed the instructions and entered command sudo docker -d, and I got this:
[/var/lib/docker|2462000b] +job initserver()
[/var/lib/docker|2462000b.initserver()] Creating server
open /var/lib/docker/aufs/layers/cf2414da53f9bcfaa48bc3d58360d7f1cfd3784e4fe51fbef95197709dfc285d: no such file or directory[/var/lib/docker|2462000b] -job initserver() = ERR (1)
2014/02/19 12:55:57 initserver: open /var/lib/docker/aufs/layers/cf2414da53f9bcfaa48bc3d58360d7f1cfd3784e4fe51fbef95197709dfc285d: no such file or directory
How do I solve the problem?
Linux
The Post-installation steps for Linux documentation reveals the following steps:
Create the docker group.
sudo groupadd docker
Add the user to the docker group.
sudo usermod -aG docker $(whoami)
Log out and log back in to ensure docker runs with correct permissions.
Start docker.
sudo service docker start
Mac OS X
As Dayel Ostraco says is necessary to add environments variables:
docker-machine start # Start virtual machine for docker
docker-machine env # It's helps to get environment variables
eval "$(docker-machine env default)" # Set environment variables
The docker-machine start command outputs the comments to guide the process.
Linux
To run docker daemon on Linux (from CLI), run:
$ sudo service docker start # Ubuntu/Debian
Note: Skip the $ character when copy and pasting.
On RedHat/CentOS, run: sudo systemctl start docker.
To initialize the "base" filesystem, run:
$ sudo service docker stop
$ sudo rm -rf /var/lib/docker
$ sudo service docker start
or manually like:
$ sudo docker -d --storage-opt dm.basesize=20G
Install docker-machine on Linux
To install machine binaries on Linux:
locally:
install -vm755 <(curl -L https://github.com/docker/machine/releases/download/v0.5.3/docker-machine_linux-amd64) $HOME/bin/docker-machine
global:
sudo bash -c 'install -vm755 <(curl -L https://github.com/docker/machine/releases/download/v0.5.3/docker-machine_linux-amd64) /usr/local/bin/docker-machine'
macOS
On macOS the docker binary is only a client and you cannot use it to run the docker daemon, because Docker daemon uses Linux-specific kernel features, therefore you can’t run Docker natively in OS X. So you have to install docker-machine in order to create VM and attach to it.
Install docker-machine on macOS
If you don't have docker-machine command yet, install it by using one of the following methods:
Using Brew command: brew install docker-machine docker.
manually from GitHub:
install -v <(curl https://github.com/docker/machine/releases/download/v0.5.3/docker-machine_linux-amd64) /usr/local/bin/docker-machine
See: Get started with Docker for Mac.
Configure docker-machine on macOS
To start Docker Machine via Homebrew, run:
brew services start docker-machine
To create a default machine (if you don't have one, see: docker-machine ls):
docker-machine create --driver virtualbox default
Then set-up the environment for the Docker client:
eval "$(docker-machine env default)"
Then double-check by listing containers:
docker ps
See: Get started with Docker Machine and a local VM.
Install Docker.app on macOS
Alternatively to above solution, you can install a Docker app by:
brew cask install docker
Check this post for more details. See also: Cannot connect to the Docker daemon on macOS
If you are running Docker on OS X, running the following eval has worked for me.
eval "$(docker-machine env default)"
If you'd prefer not to have to run this eval statement on every terminal session, you can add this to your bash_profile:
#Docker
eval "$(docker-machine env default)"
Be sure to restart the terminal session or run source on bash_profile for the changes to take effect.
After a detailed investigation, this issue seems to happen every time after Mac OS X is rebooted (or the Docker virtual machine is restarted) which prevents the Docker client from connecting to the Docker daemon.
To solve the issue, you can either:
A) Reinstall Docker Toolbox using the official installer (https://www.docker.com/products/docker-toolbox), or simply
B) Run the following commands in order:
# First make sure that the virtual machine is running
docker-machine start default
# Regenerate TLS connection certs, requires confirmation
docker-machine regenerate-certs default
# Finally, set env
eval "$(docker-machine env default)"
C) Same as (B), you can also copy and paste the following line to run all of the three commands:
docker-machine start default; docker-machine regenerate-certs default; eval "$(docker-machine env default)"
In case you get the following error:
Error getting SSH command: Something went wrong running an SSH command!
command : cat /etc/os-release
err : exit status 255
output :
just re-run the three commands another time, and it should work the second time.
This usually happens when you are not in the docker group. You can add yourself to the docker group with:
sudo usermod -aG docker yourusername
or
sudo usermod -aG docker $(whoami)
After this, you need to logout and log back into the server.
Alternatively, you can sudo every Docker command.
If all the other solutions above don't work you can try checking the ownership of /var/run/docker.sock:
ls -l /var/run/docker.sock
If you're not the owner then change ownership with the command:
sudo chown *your-username* /var/run/docker.sock
Then you can go ahead and try executing the Docker commands hassle-free :D
You can use the command
sudo service docker stop && sudo service docker start
OR
sudo service docker restart
to simply restart it.
The best way to find out why Docker isn't working will be to run the daemon manually.
$ sudo service docker stop
$ ps aux | grep docker # do this until you don't see /usr/bin/docker -d
$ /usr/bin/docker -d
The Docker daemon logs to STDOUT, so it will start spitting out whatever it's doing.
Here was what my problem was:
[8bf47e42.initserver()] Creating pidfile
2015/01/11 15:20:33 pid file found, ensure docker is not running or delete /var/run/docker.pid
This was because the instance had been cloned from another virtual machine. I just had to remove the pidfile, and everything worked afterwards.
Of course, instead of blindly assuming this will work, I'd suggest running the daemon manually one more time and reviewing the log output for any other errors before starting the service back up.
Do a ps aux | grep docker to see if the daemon is running. If not run /etc/init.d/docker start
If you get the message Can't connect to docker daemon. Is 'docker -d' running on this host?, you can check it by docker version.
If you see the information like Docker Client is running. but Docker Server is not, it's obviously you need to start the Docker server.
In CentOS, you can use service to start or stop the Docker server.
$ sudo service docker stop
$ sudo service docker start
Then, after you type docker version, you will get the information of Docker Client and Docker Server, and the Docker daemon has been started.
Use Docker CE app
macOS
Use the new Docker Community Edition app for macOS. For example:
Uninstall all Docker Homebrew packages which you've installed so far:
brew uninstall docker-compose
brew uninstall docker-machine
brew uninstall docker
Install an app manually or via Homebrew-Cask:
brew install --cask docker
Note: This app will create necessary links to docker, docker-compose, docker-machine, etc.
After running the app, checkout the a Docker whale icon in the status menu.
Now you should be able to use docker, docker-compose, docker-machine commands as usual in the Terminal.
Related:
Brew install docker does not include docker engine?
Cannot connect to the Docker daemon on macOS
Linux/Windows
Download the Docker CE from the download page and follow the instructions.
I have similar problem. I had to logout and login again to shell because I have just installed Docker and following command didn't show in my environment.
export DOCKER_HOST=127.0.0.1:4243 >> ~/.bashrc
I restart Docker after installing it:
$ sudo service docker stop
$ sudo service docker start
And it works.
I have faced this problem, and I restarted Docker using these commands:
$ sudo service docker stop
$ sudo service docker start
But I did not solve my problem, because I forgot to execute my Docker commands without sudo. For those who faces this problem, try to check that.
Try
$ sudo docker info
instead of this:
$ docker info
I have the same error and trying docker-machine regenerate-certs or eval.. did not work for me.
This on OS X 10.11.3 (El Capitan) and Docker v1.10.1. I was able to fix it only by deleting and recreating docker-machine again. Source
If running docker-machine ls, it shows you a similar output to the one below;
DOCKER
Unknown
ERRORS
Unable to query docker version: Cannot
connect to the docker engine endpoint
Try removing your Docker machine with;
docker-machine rm -f default
Where default is your Docker machine name. Then;
docker-machine create -d virtualbox default
Creates a new Docker machine.
Double check that everything looks normal now (no errors or unknown Docker) with:
docker-machine ls
Finally don't forget to run "$(docker-machine env default)" before you continue or run the Docker Quickstart Terminal which does it for you...
I knew that there are plenty of answers already in this post. Just I would like to add one simple answer that is solved the above mentioned problem .
sudo systemctl start docker
Run the above command and it will start all the docker related threads/services.
Try adding the current user to docker group:
sudo usermod -aG docker $USER
Then log out and login.
At April 2020 on MacOS Catalina, you just need to open the desktop application:
I had the same problem - "Can't connect to docker daemon." (except I didn't get any 'file not found' errors on trying to start the server.)
'ps' showed that "/usr/bin/docker -d" was still running
I realised that I'd never actually succeeded in running the server myself though. Every attempt had produced
...
2014/03/24 21:57:29 pid file found, ensure docker is not running or delete /var/run/docker.pid
So I belatedly realised that installing docker had maybe registered the daemon with upstart, which had started it for me. Hence, trying to kill the daemon to manually restart it fails (operation not permitted). So I did a
sudo kill -9 <PID>
on the daemon process. Another daemon immediately took its place, and this new one DOES now let my CLI client connect:
$ sudo docker info
Containers: 0
Images: 0
Driver: aufs
Root Dir: /var/lib/docker/aufs
Dirs: 0
WARNING: No memory limit support
WARNING: No swap limit support
Following Docker's DOC site: Manage Docker as a non-root user
1) Create Docker Group
sudo groupadd docker
2) Make user belong to docker group to get the group's privileges.
sudo usermod -aG docker $USER
Check whether the DOCKER_HOST environment variable is set for your shell.
env | grep DOCKER_HOST
If it exists,
unset DOCKER_HOST
Then this should work:
docker run hello-world
I just had the same issue, running on Amazon AWS.
Here's what I attempted:
Set up docker-machine locally with already existing AWS instance
Used generic setup
It kind of connected, but since the remote port was closed, it failed
After that, the Docker daemon refused to start up, but running dockerd did work...
It was tested following on the remote machine:
service docker start # Also restart, no success
systemctl start docker # Also restart, no success
dockerd # Success
I removed /var/lib/docker and uninstalled everything, but there was no success after reinstallation. Unfortunately I have no logs stored from failures, but docker.service just refused to start.
However, what finally solved my issue was basically:
sudo usermod -aG docker $(whoami)
I got the same problem. In CentOS 6.5:
ps aux |grep `cat /var/run/docker.pid`
If it shows no Docker daemon process exists, then I type:
docker -d
Then Ctrl + D to stop Docker. Because we use the -d option, Docker will run as daemon. Now we can do:
service docker start
Then I can do a docker pull centos. That's all.
NOTE: If these do not work, you can try yum update, and then repeat these again, because I yum install before these.
If you are running on OS X using Docker tool, follow this.
Restart the daemon and configure your environment:
docker-machine restart
And then
docker-machine env
Finally,
eval $(docker-machine env)
To test the daemon is running:
docker ps -a or docker-machine ls. This will list all containers.
The Docker Service may not be running.
If you are on a RedHat/Fedora/CentOS, please try this:
sudo systemctl start docker
If you are on Ubuntu/Debian:
sudo service start docker
Docker will start running on your host and respective port.
Run the following command:
docker context use default
To fix this issue, I had to enable the docker service:
sudo systemctl enable /usr/lib/systemd/system/docker.service
Check if you are using Docker Machine :)
Run docker-machine env default should do the trick.
Because according to documentation:
Docker Machine is a tool that lets you install Docker Engine on
virtual hosts, and manage the hosts with docker-machine commands. You
can use Machine to create Docker hosts on your local Mac or Windows
box, on your company network, in your data center, or on cloud
providers like AWS or Digital Ocean.
Using docker-machine commands, you can start, inspect, stop, and
restart a managed host, upgrade the Docker client and daemon, and
configure a Docker client to talk to your host.
Point the Machine CLI at a running, managed host, and you can run
docker commands directly on that host. For example, run
docker-machine env default to point to a host called default, follow on-screen
instructions to complete env setup, and run docker ps,
docker run hello-world, and so forth.
https://docs.docker.com/machine/overview/
I also had the same issue. The problem was in sockets allocated to docker-daemon and docker-client.
First, permission was not set for the docker-client on docker.sock You can set it using "sudo usermod -aG docker $USER"
Then check your bash file where the docker-client is running, For me it was on 0.0.0.0:2375, while docker-daemon was running on unix socket.(It was set in the configuration file of dockerd).
Just comment the bash-line and it'll work fine.
But if you want to make it work on TCP port instead of unix socket, change the configuration file of dockerd and set it on 0.0.0.0.2375 and keep the line in bash as it is if present or set it to 0.0.0.0:2375.
To fix, you need to issue the following commands in the terminal. I'll explain each step:
# Uninstall Docker from apt packages
$ sudo apt-get remove docker docker.io
# Remove it from the libraries just to be
# sure it's gone forever
$ sudo rm -rf /var/lib/docker/*
Now, if you want to simplify things and get more time, you can run my init script with the parameter installDocker:
# Pull the init script from GitHub
$ wget https://github.com/dminca/dotfiles/blob/master/init
# Add rights to run the script
$ chmod 755 init
# Just run the script with the installDocker parameter
$ ./init installDocker
A reboot is optional, but I suggest you do it to be sure all runs smoothly.
I had the same problem running Docker 1.10 on Ubuntu 14.04 and none of the given answers worked. For me, the fix was to specify the storage driver when running the Docker daemon.
sudo docker daemon --storage-driver=devicemapper

Resources