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 am now running a Docker container in my Linux machine. The dockerfile is as follows:
# 1. basic image
FROM tensorflow/tensorflow:1.12.0-devel-py3
ENV DEBIAN_FRONTEND=noninteractive LANG='en_US.UTF-8' LANGUAGE='en_US:en' LC_CTYPE="UTF-8"
# 2. apps
RUN apt update && apt install -y --no-install-recommends \
software-properties-common && \
add-apt-repository -y ppa:ubuntu-desktop/ubuntu-make && \
apt update \
&& apt install -y --no-install-recommends \
build-essential \
vim \
ubuntu-make \
&& umake ide pycharm /root/.local/share/umake/ide/pycharm
Everything goes on well, but when I enter the Docker container using the following command:
sudo docker run --ipc=host --gpus all --net=host -it -d --rm -h docker -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix:rw
-v /usr/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu, -v /usr/lib/i386-linux-gnu:/usr/lib/i386-linux-gnu
--privileged
Then I try command such as apt update, I will receive the following messages:
apt: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.27' not found (required by /usr/lib/x86_64-linux-gnu/libapt-pkg.so.5.0)
However, this will not happen if the command is invoked in the Docker image file Dockerfile. For example, at the end of the Dockerfile, if I invoke
RUN apt update && apt install -y firefox, no errors appear.
I cannot understand why only in the Docker container is GLIBC_2.27 link problem identified.
I got the answer thanks to the help of #KamilCuk.
The reason why I got this error is because my host machine is Ubuntu 18.04 and my guest machine (Container) is Ubuntu 16.04.
This is no problem, but when I enter the Container, I share the two folders between host machine and guest machine:
/usr/lib/x86_64-linux-gnu
/usr/lib/i386-linux-gnu
As a result, the guest system tries to use libraries in the host machine, which is wrong. I forgot the reason why I decide to share host machine's libraries with the guest machine. Anyway, if I disable it, everything goes on well.
I am trying to RUN sudo su - inside the Dockerfile and I get this error
/bin/sh: 1: sudo: not found
This is how my Dockerfile looks like:
FROM ubuntu:18.04
RUN sudo su -
RUN apt update && install openjdk-8-jdk
RUN wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add - && sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/kenkins.list'
RUN apt update && apt install jenkins
RUN curl -fsSL get.docker.com | /bin/bash
RUN usermod -aG docker jenkins && systemctl restart jenkins
This error comes when I try to build it.
docker build -t jenkins .
Can someone help me?
The dockerfile will run as a virtual "root" user by default, so there is no need to include any sudo command.
Since the example script contains no "-y" defaults it seems that you have simply typed the description for a manual installation into a script. This will never work. And well, in a container the application does also need to be on PID-1 which systemctl will not do.
After going through a basic tutorial on docker you will find out why.
This command seems not to be doing anything except for creating an extra layer without any useful effect.
$ cat Dockerfile
FROM ubuntu:18.04
RUN apt-get update && apt-get install openjdk-8-jdk -y
If You want to change the use privilege use USER flag in Dockerfile
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
I'm running a virtual machine in Windows Azure with the prebuild image for Ubuntu 14.04 LTS.
When I want to install Docker.io like described here:
http://blog.docker.io/2014/04/docker-in-ubuntu-ubuntu-in-docker/
The installation works but when i`m running:
sudo docker.io pull ubuntu
An error will be thrown:
Cannot connect to the Docker daemon. Is docker -d running on this host?
Can anyone help or has the similar problem?
P.S.: Can anyone with a high reputation create a Tag for Ubuntu-14.04?
Evidently the docker daemon is not running. You wanna check /etc/default/docker.conf for proper configuration and issue
sudo service docker.io start
or
sudo service docker start
depending on how they called the service
Adding myself to the docker group:
sudo usermod -a -G docker myuser
and rebooting the machine worked for me. This solution is discussed in: https://github.com/docker/docker/issues/5314
On Ubuntu 14.04, the docker.io package installs Docker 0.9.1.
According to the documentation, to install the current version use these commands:
$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9
$ sudo sh -c "echo deb https://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list"
$ sudo apt-get update
$ sudo apt-get install lxc-docker
There is also a simple script available to help with this process:
$ curl -s https://get.docker.io/ubuntu/ | sudo sh
Alternatively, check the azure-docker-registry project for an example of how to automate Azure provisioning and Docker container deployment. For instance, this Ansible playbook:
- name: create docker data directory
file: path=/mnt/data/docker state=directory
- name: store docker files in data disk
file: src=/mnt/data/docker dest=/var/lib/docker state=link
- name: add repository key
command: creates=/etc/apt/sources.list.d/docker.list apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9
- name: copy repository source file
copy: src=docker.list dest=/etc/apt/sources.list.d/docker.list
- name: install docker package
apt: name=lxc-docker update_cache=yes state=present
Also make sure to symlink the docker.io binary to docker to use the tutorials/documentation without rewriting every command.
ln -s /usr/bin/docker.io /usr/bin/docker
Run docker -d to see if it shows any error messages.
If apparmor is missing install it with sudo apt-get install apparmor
Then sudo service docker start
Hard to say but sometime official docker installation procedure fails on Ubuntu 14.04.
One can simply install docker using below given commands [Quick and Dirty]
sudo apt-get update
sudo apt-get -y install docker.io