Docker Lamp Centos7: '/bin/sh -c systemctl start httpd.service' returned a non-zero code: 1

I’m starting to work with docker to automate envorinments, then I’m trying to build a simple LAMP so the Dockerfile is the following:

FROM centos:7

ENV container=docker

RUN yum -y swap -- remove systemd-container systemd-container-libs -- install systemd systemd-libs

RUN yum -y update; yum clean all; \
(cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done); \
rm -f /lib/systemd/system/multi-user.target.wants/*;\
rm -f /etc/systemd/system/*.wants/*;\
rm -f /lib/systemd/system/local-fs.target.wants/*; \
rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
rm -f /lib/systemd/system/basic.target.wants/*;\
rm -f /lib/systemd/system/anaconda.target.wants/*;
VOLUME [ "/sys/fs/cgroup" ]

RUN yum -y update && yum clean all
RUN yum -y install firewalld httpd mariadb-server mariadb php php-mysql php-gd php-pear php-xml php-bcmath php-mbstring php-mcrypt php-php-gettext

#Enable services
RUN systemctl enable httpd.service
RUN systemctl enable mariadb.service

#start services
RUN systemctl start httpd.service
RUN systemctl start mariadb.service

#Open firewall ports
RUN firewall-cmd --permanent --add-service=http
RUN firewall-cmd --permanent --add-service=https
RUN firewall-cmd --reload


EXPOSE 80
CMD ["/usr/sbin/init"]

so when I build the image

  • Docker exec rpc error code =13 desc = invalid header field value “oci runtime error: exec failed: cannot exec a container that has run and stopped\n”
  • Kubernetes - Automatically populating CloudDNS records from service endpoints
  • Vagrant docker chef_solo provision fail on CentOS and SuSe linux
  • mysql 5.7 can't allow docker IP access on CentOS7
  • docker enterprise solution?
  • Use --build-arg value in Dockerfile FROM parameter
  • docker build -t myimage .
    

    Then when I run the code I get the following mistake:

    The command '/bin/sh -c systemctl start httpd.service' returned a non-zero code: 1
    

    When I enter to interactive mode(jumping the commands after RUN systemctl start httpd.service and rebuidling the image):

    docker run -t -i myimage /bin/bash
    

    And after try to start manually the service httpd I get the following mistake:

    Failed to get D-Bus connection: No connection to service manager.
    

    so, I don’t know what am I doing wrong?

  • Docker compose mysql connection failing
  • How can I find out which capabilities a container has been given?
  • Dockerfile and docker-compose not updating with new instructions
  • ubuntu automatic stop a daemon doesnt happening
  • Redirect application logs to docker logs
  • Docker compose port mapping
  • 2 Solutions collect form web for “Docker Lamp Centos7: '/bin/sh -c systemctl start httpd.service' returned a non-zero code: 1”

    First of all, welcome to Docker! 🙂 Loads of Docker tutorials and docs are written around Ubuntu containers, but I like Centos too.

    Ok, there are a couple of things to talk about here:

    1. You’re running up against a known issue with systemd-based Docker containers where they seem to need extra privileges to run, and even then lots of extra config is required to get them working. The Red Hat team are experimenting with some fixes (mentioned in comments) but not sure where that’s at.

      If you wish to try getting it working, these are the best instructions I’ve found, but I’ve played with this several times in the last couple of weeks and not got it working yet.

    2. What people might say is “the real issue” here is that a Docker container should not be thought of as a “mini Virtual Machine”. Docker is designed to run one “root” process per container, and the container system makes it easy to compose multiple containers together – they are small on disk, light on memory usage and easy to network together.

      Here’s a blog post from Docker which gives some background on this. There’s also the “Docker Fundamentals” docs on Dockerizing applications and Working with containers.

      So arguably the best way to proceed with the setup you’re attempting to create here (though it might sound more complicated at the beginning) is to break your “stack” up into the services you need, and then use a tool like docker-compose (introduction, documentation) to create single-purpose Docker containers as required.

      In your case above, you have two services, a web server and a database server. Therefore two Docker containers should work well, connected together by the database network connection. Here are some examples:

      • example with Symfony app, nginx and MariaDB
      • example with MariaDB + NodeJS

      If you run one service per Docker container, you don’t need to use systemd to manage them, as the Docker daemon manages each container sort of like it is a Unix process. When the process dies, the Docker container dies, and this is important because the Docker server monitors containers and can restart them automatically, or notify you.

    This looks more like a perfect example where my docker-systemctl-replacement would fit into. It can easily interpret “systemctl start httpd.service” without an active SystemD around. I have done the same for some database services but not specifically the mariadb.service – may be you could give it a try.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.