Skip to content

Commit 3722a24

Browse files
committed
working on dockerfile
1 parent 32a3079 commit 3722a24

8 files changed

+314
-0
lines changed

Diff for: .dockerignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.git

Diff for: .gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.swp
2+
.DS_Store
3+
.idea

Diff for: .ssh-default-pass

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
topix

Diff for: Dockerfile

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
FROM ubuntu:16.04
2+
MAINTAINER Alex Comunian <[email protected]>
3+
4+
# Keep upstart from complaining
5+
RUN dpkg-divert --local --rename --add /sbin/initctl
6+
RUN ln -sf /bin/true /sbin/initctl
7+
RUN mkdir /var/run/sshd
8+
RUN mkdir /run/php
9+
10+
# Let the conatiner know that there is no tty
11+
ENV DEBIAN_FRONTEND noninteractive
12+
13+
RUN apt-get update
14+
RUN apt-get -y upgrade
15+
16+
# Basic Requirements
17+
RUN apt-get -y install pwgen python-setuptools curl git nano sudo unzip openssh-server openssl vim htop
18+
RUN apt-get -y install mysql-server mysql-client nginx php-fpm php-mysql
19+
20+
# PHP Requirements
21+
RUN apt-get -y install php-xml php-mbstring php-bcmath php-zip php-pdo-mysql php-curl php-gd php-intl php-pear php-imagick php-imap php-mcrypt php-memcache php-apcu php-pspell php-recode php-tidy php-xmlrpc
22+
23+
# mysql config
24+
RUN sed -i -e"s/^bind-address\s*=\s*127.0.0.1/explicit_defaults_for_timestamp = true\nbind-address = 0.0.0.0/" /etc/mysql/mysql.conf.d/mysqld.cnf
25+
26+
# nginx config
27+
RUN sed -i -e"s/user\s*www-data;/user topix www-data;/" /etc/nginx/nginx.conf
28+
RUN sed -i -e"s/keepalive_timeout\s*65/keepalive_timeout 2/" /etc/nginx/nginx.conf
29+
RUN sed -i -e"s/keepalive_timeout 2/keepalive_timeout 2;\n\tclient_max_body_size 100m/" /etc/nginx/nginx.conf
30+
RUN echo "daemon off;" >> /etc/nginx/nginx.conf
31+
32+
# php-fpm config
33+
RUN sed -i -e "s/upload_max_filesize\s*=\s*2M/upload_max_filesize = 100M/g" /etc/php/7.0/fpm/php.ini
34+
RUN sed -i -e "s/post_max_size\s*=\s*8M/post_max_size = 100M/g" /etc/php/7.0/fpm/php.ini
35+
RUN sed -i -e "s/;daemonize\s*=\s*yes/daemonize = no/g" /etc/php/7.0/fpm/php-fpm.conf
36+
RUN sed -i -e "s/;catch_workers_output\s*=\s*yes/catch_workers_output = yes/g" /etc/php/7.0/fpm/pool.d/www.conf
37+
RUN sed -i -e "s/user\s*=\s*www-data/user = topix/g" /etc/php/7.0/fpm/pool.d/www.conf
38+
# replace # by ; RUN find /etc/php/7.0/mods-available/tmp -name "*.ini" -exec sed -i -re 's/^(\s*)#(.*)/\1;\2/g' {} \;
39+
40+
# nginx site conf
41+
ADD ./nginx-site.conf /etc/nginx/sites-available/default
42+
43+
# Supervisor Config
44+
RUN /usr/bin/easy_install supervisor
45+
RUN /usr/bin/easy_install supervisor-stdout
46+
ADD ./supervisord.conf /etc/supervisord.conf
47+
48+
# Add system user for topix
49+
RUN useradd -m -d /home/topix -p $(openssl passwd -1 'topix') -G root -s /bin/bash topix \
50+
&& usermod -a -G www-data topix \
51+
&& usermod -a -G sudo topix \
52+
&& ln -s /usr/share/nginx/www /home/topix/www
53+
54+
RUN chown -R topix:www-data /usr/share/nginx/www \
55+
&& chmod -R 775 /usr/share/nginx/www
56+
57+
# Initialization and Startup Script
58+
ADD ./start.sh /start.sh
59+
RUN chmod 755 /start.sh
60+
61+
#NETWORK PORTS
62+
# private expose
63+
EXPOSE 9011
64+
EXPOSE 3306
65+
EXPOSE 80
66+
EXPOSE 22
67+
68+
# volume for mysql database and install
69+
VOLUME ["/var/lib/mysql", "/usr/share/nginx/www", "/var/run/sshd"]
70+
71+
CMD ["/bin/bash", "/start.sh"]

Diff for: README.md

+71
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,73 @@
11
# docker-nginx-ssh-mysql-php7
22
Docker Container for NGINX / PHP7 / MYSQL / SSH
3+
4+
A Dockerfile that installs the latest Ubuntu 16.04 with nginx 1.10.0, php-fpm7.0, php7.0 APC User Cache and openssh. You can also handle the services using supervisord.
5+
6+
## Installation
7+
8+
The easiest way get up and running with this docker container is to pull the latest stable version from the [Docker Hub Registry](https://hub.docker.com/r/alexcomu/docker-nginx-ssh-mysql-php7/):
9+
10+
```bash
11+
$ docker pull alexcomu/docker-nginx-ssh-mysql-php7/:latest
12+
```
13+
14+
If you'd like to build the image yourself:
15+
16+
```bash
17+
$ git clone https://github.com/alexcomu/docker-nginx-ssh-mysql-php7.git
18+
$ cd docker-nginx-ssh-mysql-php7
19+
$ sudo docker build -t="alexcomu/docker-nginx-ssh-mysql-php7/" .
20+
```
21+
22+
## Usage
23+
24+
The -p 8000:80 maps the internal docker port 80 to the outside port 80 of the host machine. The other -p sets up sshd on port 7000.
25+
The -p 9011:9011 is using for supervisord, listing out all services status.
26+
```bash
27+
$ sudo docker run -p 7000:22 -p 8000:80 --name CONTAINER_NAME -h CONTAINER_NAME -d alexcomu/docker-nginx-ssh-mysql-php7:latest
28+
```
29+
30+
Start your newly created container, named *docker-name*.
31+
32+
```
33+
$ sudo docker start CONTAINER_NAME
34+
```
35+
36+
After starting the container docker-wordpress-nginx-ssh checks to see if it has started and the port mapping is correct. This will also report the port mapping between the docker container and the host machine.
37+
38+
```
39+
$ sudo docker ps
40+
41+
3306/tcp, 0.0.0.0:9011->9011/tcp, 0.0.0.0:7000->22/tcp, 0.0.0.0:8000->80/tcp
42+
```
43+
44+
You can then visit the following URL in a browser on your host machine to get started:
45+
46+
```
47+
http://127.0.0.1:8000
48+
```
49+
50+
You can start/stop/restart and view the error logs of nginx and php-fpm services:
51+
```
52+
http://127.0.0.1:9011
53+
```
54+
55+
You can also SSH to your container on 127.0.0.1:7000. The default password is *topix*, and can also be found in .ssh-default-pass.
56+
57+
```
58+
$ ssh -p 7000 [email protected]
59+
# To drop into root
60+
$ sudo -s
61+
```
62+
63+
Now that you've got SSH access, you can setup your FTP client the same way, or the SFTP Sublime Text plugin, for easy access to files.
64+
65+
To get the MySQL's password, check the top of the docker container logs for it:
66+
67+
```
68+
$ docker logs <container-id>
69+
```
70+
or ssh to your container and view those files:
71+
```
72+
$ cat /mysql-root-pw.txt
73+
```

Diff for: nginx-site.conf

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Upstream to abstract backend connection(s) for php
2+
upstream php {
3+
server unix:/run/php/php7.0-fpm.sock;
4+
}
5+
6+
server {
7+
listen 80; ## listen for ipv4; this line is default and implied
8+
listen [::]:80 default ipv6only=on; ## listen for ipv6
9+
10+
root /usr/share/nginx/www;
11+
12+
## This should be in your http block and if it is, it's not needed here.
13+
index index.php;
14+
15+
location = /favicon.ico {
16+
log_not_found off;
17+
access_log off;
18+
}
19+
20+
location = /robots.txt {
21+
allow all;
22+
log_not_found off;
23+
access_log off;
24+
}
25+
26+
location / {
27+
try_files $uri $uri/ /index.php?$args;
28+
}
29+
30+
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
31+
#
32+
location ~ \.php$ {
33+
# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
34+
include snippets/fastcgi-php.conf;
35+
36+
fastcgi_intercept_errors on;
37+
fastcgi_pass php;
38+
}
39+
40+
#WPMU Files
41+
location ~ ^/files/(.*)$ {
42+
try_files /wp-content/blogs.dir/$blogid/$uri /wp-includes/ms-files.php?file=$1 ;
43+
access_log off;
44+
log_not_found off;
45+
expires max;
46+
}
47+
48+
#WPMU x-sendfile to avoid php readfile()
49+
location ^~ /blogs.dir {
50+
internal;
51+
alias /var/www/example.com/htdocs/wp-content/blogs.dir;
52+
access_log off;
53+
log_not_found off;
54+
expires max;
55+
}
56+
57+
# deny access to .htaccess files, if Apache's document root
58+
# concurs with nginx's one
59+
#
60+
location ~ /\.ht {
61+
deny all;
62+
}
63+
64+
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
65+
expires max;
66+
log_not_found off;
67+
}
68+
}

Diff for: start.sh

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
# mysql setup
4+
if [ ! -f /setup.txt ]; then
5+
#mysql has to be started this way as it doesn't work to call from /etc/init.d
6+
/usr/bin/mysqld_safe &
7+
sleep 10s
8+
# Here we generate random passwords (thank you pwgen!) for mysql users
9+
MYSQL_PASSWORD=`pwgen -c -n -1 12`
10+
#This is so the passwords show up in logs.
11+
echo mysql root password: $MYSQL_PASSWORD
12+
echo $MYSQL_PASSWORD > /mysql-root-pw.txt
13+
echo "SETUPOK" > /setup.txt
14+
15+
mysqladmin -u root password $MYSQL_PASSWORD
16+
mysql -uroot -p$MYSQL_PASSWORD -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '$MYSQL_PASSWORD' WITH GRANT OPTION; FLUSH PRIVILEGES;"
17+
mysql -uroot -p$MYSQL_PASSWORD -e "CREATE DATABASE wordpress; GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpress'@'localhost' IDENTIFIED BY '$WORDPRESS_PASSWORD'; FLUSH PRIVILEGES;"
18+
killall mysqld
19+
fi
20+
21+
# start all the services
22+
/usr/local/bin/supervisord -n -c /etc/supervisord.conf

Diff for: supervisord.conf

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
[unix_http_server]
2+
file=/tmp/supervisor.sock ; (the path to the socket file)
3+
;chmod=0700 ; sockef file mode (default 0700)
4+
;chown=nobody:nogroup ; socket file uid:gid owner
5+
;username=user ; (default is no username (open server))
6+
;password=123 ; (default is no password (open server))
7+
8+
[inet_http_server] ; inet (TCP) server disabled by default
9+
port=9011 ; (ip_address:port specifier, *:port for all iface)
10+
;username=user ; (default is no username (open server))
11+
;password=123 ; (default is no password (open server))
12+
13+
[supervisord]
14+
logfile=/tmp/supervisord.log ; (main log file;default $CWD/supervisord.log)
15+
logfile_maxbytes=50MB ; (max main logfile bytes b4 rotation;default 50MB)
16+
logfile_backups=10 ; (num of main logfile rotation backups;default 10)
17+
loglevel=info ; (log level;default info; others: debug,warn,trace)
18+
pidfile=/tmp/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
19+
nodaemon=false ; (start in foreground if true;default false)
20+
minfds=1024 ; (min. avail startup file descriptors;default 1024)
21+
minprocs=200 ; (min. avail process descriptors;default 200)
22+
23+
; the below section must remain in the config file for RPC
24+
; (supervisorctl/web interface) to work, additional interfaces may be
25+
; added by defining them in separate rpcinterface: sections
26+
[rpcinterface:supervisor]
27+
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
28+
29+
[supervisorctl]
30+
serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL for a unix socket
31+
; serverurl=http://localhost:9011
32+
33+
[program:php-fpm7.0]
34+
command=/usr/sbin/php-fpm7.0 -c /etc/php/7.0/fpm/php-fpm.conf
35+
; autostart=true
36+
; autorestart=true
37+
; priority=5
38+
; stdout_logfile=/dev/stdout
39+
; stdout_logfile_maxbytes=0
40+
; stderr_logfile=/dev/stderr
41+
; stderr_logfile_maxbytes=0
42+
stdout_events_enabled=true
43+
stderr_events_enabled=true
44+
stdout_logfile_maxbytes=0
45+
46+
[program:php7-fpm-log]
47+
command=tail -f /var/log/php7.0-fpm.log
48+
stdout_events_enabled=true
49+
stderr_events_enabled=true
50+
stdout_logfile_maxbytes=0
51+
52+
[program:mysqld]
53+
command=/usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/mysql/plugin --user=mysql --log-error=/var/log/mysql/error.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/run/mysqld/mysqld.sock --port=3306
54+
stdout_events_enabled=true
55+
stderr_events_enabled=true
56+
stdout_logfile_maxbytes=0
57+
58+
[program:mysqld-error-log]
59+
command=tail -f /var/log/mysql/error.log
60+
stdout_events_enabled=true
61+
stderr_events_enabled=true
62+
stdout_logfile_maxbytes=0
63+
64+
[program:nginx]
65+
command=/usr/sbin/nginx
66+
stdout_events_enabled=true
67+
stderr_events_enabled=true
68+
stdout_logfile_maxbytes=0
69+
70+
[program:ssh]
71+
command=/usr/sbin/sshd -D
72+
73+
[eventlistener:stdout]
74+
command = supervisor_stdout
75+
buffer_size = 100
76+
events = PROCESS_LOG
77+
result_handler = supervisor_stdout:event_handler

0 commit comments

Comments
 (0)