6-3 compose实战

6-3 compose实战

vim Dockerfile

FROM ghost
COPY ./config.js /var/lib/ghost/config.js
EXPOSE 2368
CMD ["npm", "start", "--production"]

vim config.js

var path = require('path'),
config; 
config = {
  production:{
    url:'http://mytestblog.com',
    mail:{},
    database:{
        client:'mysql',
        connection:{
         host:'db',
         user:'ghost',
         password:'ghost',
         database:'ghost',
         port:'3306',
         charset"utf-8'
        },
        debug:false
    },
    paths:{
      contentPath:path.join(process,env.GHOST_CONTENT,'/')
    },
    server:{
      host:'0.0.0.0",
      port:'2368'
    }
  }     


};

module.exports = config;

拷贝文件到当前目录下

cp ../../config.js .
root@iZbp1berl2oy3e3vt5476fZ:~/ghost/nginx# touch Dockerfile
root@iZbp1berl2oy3e3vt5476fZ:~/ghost/nginx# vim Dockerfile 
root@iZbp1berl2oy3e3vt5476fZ:~/ghost/nginx# pwd
/root/ghost/nginx
root@iZbp1berl2oy3e3vt5476fZ:~/ghost/nginx# 
FROM nginx
COPY nginx.conf /etc/nginx/nginx.conf
EXPOSE 80
root@iZbp1berl2oy3e3vt5476fZ:~/ghost/nginx# touch nginx.conf
root@iZbp1berl2oy3e3vt5476fZ:~/ghost/nginx# vim nginx.conf 
root@iZbp1berl2oy3e3vt5476fZ:~/ghost/nginx# pwd
/root/ghost/nginx
root@iZbp1berl2oy3e3vt5476fZ:~/ghost/nginx# 
worker processer 4;
events {worker connections 1024;}
http{
        server{
                listen 80;
                location / {
                        proxy pass http://ghost-app:2368;
                }
        }
}
扫描二维码关注公众号,回复: 12962517 查看本文章
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# touch docker-compose.yml
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# vim docker-compose.yml 
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# pwd
/root/ghost
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# 
version: '2'

networks:
        - ghost
          
services: 
        ghost-app:
                build: ghost
                networks:
                  - ghost
                depends_on:
                  - db
                ports:
                  - "2368:2368"

         nginx:
                 build: nginx
                 networks:
                   - ghost
                 depends_on:
                   - ghost-app
                 ports:
                   - "80:80"

         db:
                 image: "mysql:5.7.15"
                 networks:
                         - ghost
                 environment:
                         MYSQL_ROOT_PASSWORD: mysqlroot
                         MYSQL_USER: ghost
                         MYSQL_PASSWORD: ghost
                 volumes:
                         - $PWD/data:/var/libmysql
                 ports:
                         - "3306:3306"

代码有问题:没有对齐

先卸载

Ubuntu18.04彻底删除MySQL数据库

1.首先在终端中查看MySQL的依赖项:dpkg --list|grep mysql

2.卸载: sudo apt-get remove mysql-common

3.卸载:sudo apt-get autoremove --purge mysql-server-5.7

4.清除残留数据:dpkg -l|grep ^rc|awk '{print$2}'|sudo xargs dpkg -P

5.再次查看MySQL的剩余依赖项:dpkg --list|grep mysql

6.继续删除剩余依赖项,如:sudo apt-get autoremove --purge mysql-apt-config

docker-compose up -d

worker_processer 4;
events {worker_connections 1024;}
http{
        server{
                listen 80;
                location / {
                        proxy_pass http://ghost-app:2368;
                }
        }
}
docker-compose stop

重新构建

docker-compose build

图示:

root@iZbp1berl2oy3e3vt5476fZ:~# pwd
/root
root@iZbp1berl2oy3e3vt5476fZ:~# mkdir ghost
root@iZbp1berl2oy3e3vt5476fZ:~# cd ghost/
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# ls
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# pwd
/root/ghost
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# mkdir ghost
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# mkdir nginx
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# mkdir data
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# ls
data  ghost  nginx
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# pwd
/root/ghost
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# cd ghost/
root@iZbp1berl2oy3e3vt5476fZ:~/ghost/ghost# ls
root@iZbp1berl2oy3e3vt5476fZ:~/ghost/ghost# touch Dockerfile
root@iZbp1berl2oy3e3vt5476fZ:~/ghost/ghost# vim Dockerfile 
root@iZbp1berl2oy3e3vt5476fZ:~/ghost/ghost# pwd
/root/ghost/ghost
root@iZbp1berl2oy3e3vt5476fZ:~/ghost/ghost# cd
root@iZbp1berl2oy3e3vt5476fZ:~# pwd
/root
root@iZbp1berl2oy3e3vt5476fZ:~# touch config.js
root@iZbp1berl2oy3e3vt5476fZ:~# vim config.js 
root@iZbp1berl2oy3e3vt5476fZ:~# cd ghost/ghost/
root@iZbp1berl2oy3e3vt5476fZ:~/ghost/ghost# pwd
/root/ghost/ghost
root@iZbp1berl2oy3e3vt5476fZ:~/ghost/ghost# cp ../../config.js .
root@iZbp1berl2oy3e3vt5476fZ:~/ghost/ghost# ls
config.js  Dockerfile
root@iZbp1berl2oy3e3vt5476fZ:~/ghost/ghost# pwd
/root/ghost/ghost
root@iZbp1berl2oy3e3vt5476fZ:~/ghost/ghost# cd ..
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# ls
data  ghost  nginx
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# cd nginx/
root@iZbp1berl2oy3e3vt5476fZ:~/ghost/nginx# touch Dockerfile
root@iZbp1berl2oy3e3vt5476fZ:~/ghost/nginx# vim Dockerfile 
root@iZbp1berl2oy3e3vt5476fZ:~/ghost/nginx# pwd
/root/ghost/nginx
root@iZbp1berl2oy3e3vt5476fZ:~/ghost/nginx# touch nginx.conf
root@iZbp1berl2oy3e3vt5476fZ:~/ghost/nginx# vim nginx.conf 
root@iZbp1berl2oy3e3vt5476fZ:~/ghost/nginx# pwd
/root/ghost/nginx
root@iZbp1berl2oy3e3vt5476fZ:~/ghost/nginx# cd ..
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# pwd
/root/ghost
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# touch docker-compose.yml
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# vim docker-compose.yml 
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# pwd
/root/ghost
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# ls
data  docker-compose.yml  ghost  nginx
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# vi docker-compose.yml 
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# ls
data  docker-compose.yml  ghost  nginx
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# docker-compose up -d
ERROR: yaml.parser.ParserError: while parsing a block mapping
  in "./docker-compose.yml", line 7, column 9
expected <block end>, but found '<block mapping start>'
  in "./docker-compose.yml", line 16, column 10
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# vim docker-compose.yml 
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# docker-compose up -d
ERROR: yaml.parser.ParserError: while parsing a block mapping
  in "./docker-compose.yml", line 7, column 9
expected <block end>, but found '<block mapping start>'
  in "./docker-compose.yml", line 16, column 10
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# vim docker-compose.yml 
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# docker-compose up -d
Creating network "ghost_ghost" with the default driver
Pulling db (mysql:5.7.15)...
5.7.15: Pulling from library/mysql
6a5a5368e0c2: Pull complete
0689904e86f0: Pull complete
486087a8071d: Pull complete
3eff318f6785: Pull complete
3df41d8a4cfb: Pull complete
1b4a00485931: Pull complete
0bab0b2c2630: Pull complete
264fc9ce512d: Pull complete
e0181dcdbbe8: Pull complete
53b082fa47c7: Pull complete
e5cf4fe00c4c: Pull complete
Digest: sha256:966490bda4576655dc940923c4883db68cca0b3607920be5efff7514e0379aa7
Status: Downloaded newer image for mysql:5.7.15
Building ghost-app
Step 1/4 : FROM ghost
latest: Pulling from library/ghost

45d607bea48c: Pull complete
41fb1554a069: Pull complete
b0c9c4030d8b: Pull complete
5e269c64de4a: Pull complete
2830ddc26eaa: Pull complete
9c44da4a88ae: Pull complete
ec44662cefe4: Pull complete
4ddc66feb5f6: Pull complete
Digest: sha256:00c8be8f8fda4f350f819f0dbdf6447e6ade655aa27e4be654f4d0be6745eda2
Status: Downloaded newer image for ghost:latest
 ---> 010c18728860
Step 2/4 : COPY ./config.js /var/lib/ghost/config.js
 ---> 0fdff9797135
Step 3/4 : EXPOSE 2368
 ---> Running in eaf3ee838800
Removing intermediate container eaf3ee838800
 ---> 4493cb379463
Step 4/4 : CMD ["npm", "start", "--production"]
 ---> Running in 874bbb367a2a
Removing intermediate container 874bbb367a2a
 ---> 0536086bf0f8
Successfully built 0536086bf0f8
Successfully tagged ghost_ghost-app:latest
WARNING: Image for service ghost-app was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
Building nginx
Step 1/3 : FROM nginx
 ---> 6084105296a9
Step 2/3 : COPY nginx.conf /etc/nginx/nginx.conf
 ---> 6c23db5b1efb
Step 3/3 : EXPOSE 80
 ---> Running in b848099a0cae
Removing intermediate container b848099a0cae
 ---> 9f25f957a7ea
Successfully built 9f25f957a7ea
Successfully tagged ghost_nginx:latest
WARNING: Image for service nginx was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
Creating ghost_db_1

ERROR: for db  Cannot start service db: driver failed programming external connectivity on endpoint ghost_db_1 (0b0b7a4e5eb0d3b95b62db433a2c351575923b7417fd6c9e6eb4fb6baccccfe5): Error starting userland proxy: listen tcp4 0.0.0.0:3306: bind: address already in use
ERROR: Encountered errors while bringing up the project.
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# docker-compose build
db uses an image, skipping
Building ghost-app
Step 1/4 : FROM ghost
 ---> 010c18728860
Step 2/4 : COPY ./config.js /var/lib/ghost/config.js
 ---> Using cache
 ---> 0fdff9797135
Step 3/4 : EXPOSE 2368
 ---> Using cache
 ---> 4493cb379463
Step 4/4 : CMD ["npm", "start", "--production"]
 ---> Using cache
 ---> 0536086bf0f8
Successfully built 0536086bf0f8
Successfully tagged ghost_ghost-app:latest
Building nginx
Step 1/3 : FROM nginx
 ---> 6084105296a9
Step 2/3 : COPY nginx.conf /etc/nginx/nginx.conf
 ---> Using cache
 ---> 6c23db5b1efb
Step 3/3 : EXPOSE 80
 ---> Using cache
 ---> 9f25f957a7ea
Successfully built 9f25f957a7ea
Successfully tagged ghost_nginx:latest
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# docker-compose up -d
Starting ghost_db_1

ERROR: for db  Cannot start service db: driver failed programming external connectivity on endpoint ghost_db_1 (96b66820d55e5693a2bd3a8467ec92c346d8eaae52f59468ca0c24728675eed8): Error starting userland proxy: listen tcp4 0.0.0.0:3306: bind: address already in use
ERROR: Encountered errors while bringing up the project.
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# ps -ef|grep mysql
mysql     3988     1  0 Mar10 ?        00:06:46 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid
root     20955 20228  0 22:10 pts/4    00:00:00 grep --color=auto mysql
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# kill -9 3988
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# ps -ef|grep mysql
mysql    20994     1  0 22:10 ?        00:00:00 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid
mysql    20996     1  0 22:10 ?        00:00:00 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid
root     21011 20228  0 22:10 pts/4    00:00:00 grep --color=auto mysql
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# kill -9 20994
-bash: kill: (20994) - No such process
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# ps -ef|grep mysql
mysql    20996     1  1 22:10 ?        00:00:00 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid
root     21028 20228  0 22:11 pts/4    00:00:00 grep --color=auto mysql
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# kill -9 20996
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# ps -ef|grep mysql
mysql    21064     1 12 22:11 ?        00:00:00 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid
root     21095 20228  0 22:11 pts/4    00:00:00 grep --color=auto mysql
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# kill -9 21095 21064
-bash: kill: (21095) - No such process
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# ps -ef|grep mysql
mysql    21130     1  8 22:11 ?        00:00:00 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid
root     21163 20228  0 22:11 pts/4    00:00:00 grep --color=auto mysql
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# docker-compose up -d
Starting ghost_db_1

ERROR: for db  Cannot start service db: driver failed programming external connectivity on endpoint ghost_db_1 (85fe560463076688e61802760a11d6d7799eaebbad70dd7ba7566a4ab213d8b8): Error starting userland proxy: listen tcp4 0.0.0.0:3306: bind: address already in use
ERROR: Encountered errors while bringing up the project.
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# dpkg --list|grep mysql
ii  libmysqlclient20:amd64                 5.7.32-0ubuntu0.18.04.1                         amd64        MySQL database client library
ii  mysql-client-5.7                       5.7.33-0ubuntu0.18.04.1                         amd64        MySQL database client binaries
ii  mysql-client-core-5.7                  5.7.33-0ubuntu0.18.04.1                         amd64        MySQL database core client binaries
ii  mysql-common                           5.8+1.0.4                                       all          MySQL database common files, e.g. /etc/mysql/my.cnf
ii  mysql-server                           5.7.33-0ubuntu0.18.04.1                         all          MySQL database server (metapackage depending on the latest version)
ii  mysql-server-5.7                       5.7.33-0ubuntu0.18.04.1                         amd64        MySQL database server binaries and system database setup
ii  mysql-server-core-5.7                  5.7.33-0ubuntu0.18.04.1                         amd64        MySQL database server binaries
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# sudo apt-get remove mysql-common
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  alien at bc cups-bsd cups-client cups-common debhelper debugedit dh-autoreconf dh-strip-nondeterminism guile-2.0-libs intltool-debian libarchive-cpio-perl
  libarchive-zip-perl libarchive13 libcgi-fast-perl libcgi-pm-perl libcups2 libcupsfilters1 libcupsimage2 libencode-locale-perl libevent-core-2.1-6 libfcgi-perl
  libfile-stripnondeterminism-perl libgc1c2 libgsasl7 libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl libhttp-date-perl libhttp-message-perl libio-html-perl
  libkyotocabinet16v5 liblua5.2-0 liblwp-mediatypes-perl liblzo2-2 libmail-sendmail-perl libntlm0 librpm8 librpmbuild8 librpmio8 librpmsign8 libsys-hostname-long-perl
  libtimedate-perl liburi-perl lsb-security mailutils-common mysql-client-core-5.7 mysql-server-core-5.7 pax po-debconf rpm rpm-common rpm2cpio
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
  libmailutils5 libmysqlclient20 lsb-core mailutils mysql-client-5.7 mysql-common mysql-server mysql-server-5.7
0 upgraded, 0 newly installed, 8 to remove and 56 not upgraded.
After this operation, 86.1 MB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 112216 files and directories currently installed.)
Removing lsb-core (9.20170808ubuntu1) ...
Removing mailutils (1:3.4-1) ...
update-alternatives: using /usr/bin/bsd-from to provide /usr/bin/from (from) in auto mode
Removing libmailutils5:amd64 (1:3.4-1) ...
Removing libmysqlclient20:amd64 (5.7.32-0ubuntu0.18.04.1) ...
Removing mysql-server (5.7.33-0ubuntu0.18.04.1) ...
Removing mysql-server-5.7 (5.7.33-0ubuntu0.18.04.1) ...
update-alternatives: using /etc/mysql/my.cnf.fallback to provide /etc/mysql/my.cnf (my.cnf) in auto mode
Removing mysql-client-5.7 (5.7.33-0ubuntu0.18.04.1) ...
Removing mysql-common (5.8+1.0.4) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Processing triggers for libc-bin (2.27-3ubuntu1.4) ...
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# sudo apt-get autoremove --purge mysql-server-5.7
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  alien* at* bc* cups-bsd* cups-client* cups-common* debhelper* debugedit* dh-autoreconf* dh-strip-nondeterminism* guile-2.0-libs* intltool-debian* libarchive-cpio-perl*
  libarchive-zip-perl* libarchive13* libcgi-fast-perl* libcgi-pm-perl* libcups2* libcupsfilters1* libcupsimage2* libencode-locale-perl* libevent-core-2.1-6* libfcgi-perl*
  libfile-stripnondeterminism-perl* libgc1c2* libgsasl7* libhtml-parser-perl* libhtml-tagset-perl* libhtml-template-perl* libhttp-date-perl* libhttp-message-perl*
  libio-html-perl* libkyotocabinet16v5* liblua5.2-0* liblwp-mediatypes-perl* liblzo2-2* libmail-sendmail-perl* libntlm0* librpm8* librpmbuild8* librpmio8* librpmsign8*
  libsys-hostname-long-perl* libtimedate-perl* liburi-perl* lsb-security* mailutils-common* mysql-client-core-5.7* mysql-server-5.7* mysql-server-core-5.7* pax* po-debconf*
  rpm* rpm-common* rpm2cpio*
0 upgraded, 0 newly installed, 55 to remove and 56 not upgraded.
After this operation, 106 MB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 111998 files and directories currently installed.)
Removing alien (8.95) ...
Removing at (3.1.20-3.1ubuntu2) ...
Removing bc (1.07.1-2) ...
Removing cups-bsd (2.2.7-1ubuntu2.8) ...
Removing cups-client (2.2.7-1ubuntu2.8) ...
Removing cups-common (2.2.7-1ubuntu2.8) ...
Removing rpm (4.14.1+dfsg1-2) ...
Removing debugedit (4.14.1+dfsg1-2) ...
Removing guile-2.0-libs:amd64 (2.0.13+1-5ubuntu0.1) ...
Removing libarchive-cpio-perl (0.10-1) ...
Removing rpm2cpio (4.14.1+dfsg1-2) ...
Removing libarchive13:amd64 (3.2.2-3.1ubuntu0.6) ...
Removing libcgi-fast-perl (1:2.13-1) ...
Removing libhtml-template-perl (2.97-1) ...
Removing libcgi-pm-perl (4.38-1) ...
Removing libcupsimage2:amd64 (2.2.7-1ubuntu2.8) ...
Removing libcupsfilters1:amd64 (1.20.2-0ubuntu3.1) ...
Removing libcups2:amd64 (2.2.7-1ubuntu2.8) ...
Removing libhttp-message-perl (6.14-1) ...
Removing libencode-locale-perl (1.05-1) ...
Removing libevent-core-2.1-6:amd64 (2.1.8-stable-4build1) ...
Removing libfcgi-perl (0.78-2build1) ...
Removing libgc1c2:amd64 (1:7.4.2-8ubuntu1) ...
Removing libgsasl7:amd64 (1.8.0-8ubuntu3) ...
Removing libhtml-parser-perl (3.72-3build1) ...
Removing libhtml-tagset-perl (3.20-3) ...
Removing libhttp-date-perl (6.02-1) ...
Removing libio-html-perl (1.001-1) ...
Removing libkyotocabinet16v5:amd64 (1.2.76-4.2) ...
Removing rpm-common (4.14.1+dfsg1-2) ...
Removing librpmsign8 (4.14.1+dfsg1-2) ...
Removing librpmbuild8 (4.14.1+dfsg1-2) ...
Removing librpm8 (4.14.1+dfsg1-2) ...
Removing liblwp-mediatypes-perl (6.02-1) ...
Removing liblzo2-2:amd64 (2.08-1.2) ...
Removing libmail-sendmail-perl (0.80-1) ...
Removing libntlm0:amd64 (1.4-8) ...
Removing libsys-hostname-long-perl (1.5-1) ...
Removing liburi-perl (1.73-1) ...
Removing lsb-security (9.20170808ubuntu1) ...
Removing mailutils-common (1:3.4-1) ...
Removing mysql-client-core-5.7 (5.7.33-0ubuntu0.18.04.1) ...
Removing mysql-server-core-5.7 (5.7.33-0ubuntu0.18.04.1) ...
Removing pax (1:20171021-2) ...
Removing librpmio8 (4.14.1+dfsg1-2) ...
Removing liblua5.2-0:amd64 (5.2.4-1.1build1) ...
Removing dh-autoreconf (17) ...
Removing debhelper (11.1.6ubuntu2) ...
Removing dh-strip-nondeterminism (0.040-1.1~build1) ...
Removing po-debconf (1.0.20) ...
Removing intltool-debian (0.35.0+20060710.4) ...
Removing libfile-stripnondeterminism-perl (0.040-1.1~build1) ...
Removing libarchive-zip-perl (1.60-1ubuntu0.1) ...
Removing libtimedate-perl (2.3000-2) ...
Processing triggers for libc-bin (2.27-3ubuntu1.4) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Processing triggers for install-info (6.5.0.dfsg.1-2) ...
(Reading database ... 109746 files and directories currently installed.)
Purging configuration files for rpm (4.14.1+dfsg1-2) ...
Purging configuration files for at (3.1.20-3.1ubuntu2) ...
Purging configuration files for cups-bsd (2.2.7-1ubuntu2.8) ...
Purging configuration files for mysql-server-5.7 (5.7.33-0ubuntu0.18.04.1) ...
Purging configuration files for bc (1.07.1-2) ...
Purging configuration files for liblzo2-2:amd64 (2.08-1.2) ...
Processing triggers for systemd (237-3ubuntu10.44) ...
Processing triggers for ureadahead (0.100.0-21) ...
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# dpkg -l|grep ^rc|awk '{print$2}'|sudo xargs dpkg -P
(Reading database ... 109728 files and directories currently installed.)
Purging configuration files for mysql-common (5.8+1.0.4) ...
Purging configuration files for ntp (1:4.2.8p10+dfsg-5ubuntu7.3) ...
Processing triggers for systemd (237-3ubuntu10.44) ...
Processing triggers for ureadahead (0.100.0-21) ...
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# dpkg --list|grep mysql
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# sudo apt-get autoremove --purge mysql-apt-config
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package mysql-apt-config
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# docker-compose up -d
Starting ghost_db_1
Creating ghost_ghost-app_1
Creating ghost_nginx_1

ERROR: for nginx  Cannot start service nginx: driver failed programming external connectivity on endpoint ghost_nginx_1 (50f094441776c16da98d7faae17cf823f1cf7f4bb75f12715eec947688f94af2): Bind for 0.0.0.0:80 failed: port is already allocated
ERROR: Encountered errors while bringing up the project.
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# ps -ef|grep python
root       593     1  0 Mar10 ?        00:00:00 /usr/bin/python3 /usr/bin/networkd-dispatcher --run-startup-triggers
root     20071     1  0 Mar16 ?        00:00:00 python3.6 manage.py runserver 0.0.0.0:90
root     20073 20071  3 Mar16 ?        08:33:22 /usr/bin/python3.6 manage.py runserver 0.0.0.0:90
root     24259 20228  0 22:19 pts/4    00:00:00 grep --color=auto python
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# docker images
REPOSITORY              TAG       IMAGE ID       CREATED          SIZE
ghost_nginx             latest    9f25f957a7ea   12 minutes ago   133MB
ghost_ghost-app         latest    0536086bf0f8   12 minutes ago   446MB
ghost                   latest    010c18728860   14 hours ago     446MB
root/hello-nginx        latest    795b366fe48d   3 days ago       160MB
hello_docker            latest    71256a536e16   3 days ago       5.61MB
<none>                  <none>    8a688aaab432   3 days ago       5.61MB
nginx-fun-hlg           latest    1d0b6ec5c36a   3 days ago       133MB
nginx                   latest    6084105296a9   13 days ago      133MB
ubuntu                  latest    4dd97cefde62   3 weeks ago      72.9MB
alpine                  latest    28f6e2705743   5 weeks ago      5.61MB
mysql                   5.7.15    18f13d72f7f0   4 years ago      383MB
docker/whalesay         latest    6b362a9f73eb   5 years ago      247MB
hlg/whalesay            latest    6b362a9f73eb   5 years ago      247MB
huanglianggu/whalesay   latest    6b362a9f73eb   5 years ago      247MB
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# docker rm root/hello-nginx hello_docker nginx-fun-hlg nginx ubuntu
Error: No such container: root/hello-nginx
Error: No such container: hello_docker
Error: No such container: nginx-fun-hlg
Error: No such container: nginx
Error: No such container: ubuntu
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# docker rm root/hello-nginx 
Error: No such container: root/hello-nginx
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# docker ps
CONTAINER ID   IMAGE          COMMAND                  CREATED          STATUS         PORTS                    NAMES
48a5d92d2609   mysql:5.7.15   "docker-entrypoint.s…"   15 minutes ago   Up 4 minutes   0.0.0.0:3306->3306/tcp   ghost_db_1
99c67905cc7e   nginx          "/docker-entrypoint.…"   2 days ago       Up 2 days      0.0.0.0:80->80/tcp       gallant_buck
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# docker rm 99c67905cc7e
Error response from daemon: You cannot remove a running container 99c67905cc7e831f1ba2cf5c99438ebcdf47f5ab348b2386ba8244d7f645c73b. Stop the container before attempting removal or force remove
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# docker stop 99c67905cc7e
99c67905cc7e
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# docker rm 99c67905cc7e
99c67905cc7e
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# docker-compose up -d
ghost_db_1 is up-to-date
Starting ghost_ghost-app_1
Starting ghost_nginx_1
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# ls
data  docker-compose.yml  ghost  nginx
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# vim docker-compose.yml 
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# docker-compose up -d
Recreating ghost_db_1
WARNING: Service "db" is using volume "/var/lib/mysql" from the previous container. Host mapping "/root/ghost/data" has no effect. Remove the existing containers (with `docker-compose rm db`) to use the host volume mapping.
Recreating ghost_ghost-app_1
Recreating ghost_nginx_1
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# docker-compose rm db
No stopped containers
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# docker ps
CONTAINER ID   IMAGE          COMMAND                  CREATED              STATUS              PORTS                    NAMES
34ef45c700f9   mysql:5.7.15   "docker-entrypoint.s…"   About a minute ago   Up About a minute   0.0.0.0:3306->3306/tcp   ghost_db_1
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# docker stop 34ef45c700f9
34ef45c700f9
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# docker-compose rm db
Going to remove ghost_db_1
Are you sure? [yN] y
Removing ghost_db_1 ... done
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# docker-compose up -d
Creating ghost_db_1
Recreating ghost_ghost-app_1
Recreating ghost_nginx_1
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# ls
data  docker-compose.yml  ghost  nginx
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# cd nginx/
root@iZbp1berl2oy3e3vt5476fZ:~/ghost/nginx# ls
Dockerfile  nginx.conf
root@iZbp1berl2oy3e3vt5476fZ:~/ghost/nginx# vim nginx.conf 
root@iZbp1berl2oy3e3vt5476fZ:~/ghost/nginx# ..
..: command not found
root@iZbp1berl2oy3e3vt5476fZ:~/ghost/nginx# docker-compose stop
Stopping ghost_db_1 ... done
root@iZbp1berl2oy3e3vt5476fZ:~/ghost/nginx# docker-compose rm
Going to remove ghost_nginx_1, ghost_ghost-app_1, ghost_db_1
Are you sure? [yN] y
Removing ghost_nginx_1 ... done
Removing ghost_ghost-app_1 ... done
Removing ghost_db_1 ... done
root@iZbp1berl2oy3e3vt5476fZ:~/ghost/nginx# cd ..
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# docker-compose build
db uses an image, skipping
Building ghost-app
Step 1/4 : FROM ghost
 ---> 010c18728860
Step 2/4 : COPY ./config.js /var/lib/ghost/config.js
 ---> Using cache
 ---> 0fdff9797135
Step 3/4 : EXPOSE 2368
 ---> Using cache
 ---> 4493cb379463
Step 4/4 : CMD ["npm", "start", "--production"]
 ---> Using cache
 ---> 0536086bf0f8
Successfully built 0536086bf0f8
Successfully tagged ghost_ghost-app:latest
Building nginx
Step 1/3 : FROM nginx
 ---> 6084105296a9
Step 2/3 : COPY nginx.conf /etc/nginx/nginx.conf
 ---> 97598fde4caa
Step 3/3 : EXPOSE 80
 ---> Running in 77f569a830c3
Removing intermediate container 77f569a830c3
 ---> 2c6c72743437
Successfully built 2c6c72743437
Successfully tagged ghost_nginx:latest
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# docker-compose up -d
Creating ghost_db_1
Creating ghost_ghost-app_1
Creating ghost_nginx_1
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# docker-compose ps
      Name                     Command                State             Ports          
--------------------------------------------------------------------------------------
ghost_db_1          docker-entrypoint.sh mysqld      Up         0.0.0.0:3306->3306/tcp 
ghost_ghost-app_1   docker-entrypoint.sh npm s ...   Exit 254                          
ghost_nginx_1       /docker-entrypoint.sh ngin ...   Exit 1                            
root@iZbp1berl2oy3e3vt5476fZ:~/ghost# curl http://localhost
curl: (7) Failed to connect to localhost port 80: Connection refused
root@iZbp1berl2oy3e3vt5476fZ:~/ghost#

猜你喜欢

转载自blog.csdn.net/huanglianggu/article/details/115217676
6-3