Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
384 views
in Technique[技术] by (71.8m points)

Docker working on localhost but have an empty containers running list

Yesterday I decided to learn docker and use it for a prestashop project so I created a docker-compose.yml my goal was to run a prestashop with a phpmyadmin and mysql all linked together.

Before leaving yesterday I didn't want to lose everything I had done so I ran a docker save and a docker commit, so I thought whenever I come back I can just run the save I made and run it without losing anything (like a snapshot).

Everything was working, containers were running and today when I try to run a docker ps -a I have an empty output. However my project is still working on localhost:8080 for prestashop and localhost:8081 for my phpmyadmin.

How could I find back the containers and also save them so I can use them on another computer?

docker-compose.yml :

version: "3.8"
 services:
  db:
    image: mysql:latest
    command: --default-authentication-plugin=mysql_native_password
    container_name: db
    restart: always
    volumes:
      - db-data:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=root
    networks:
      - dev

  phpmyadmin:
    image: phpmyadmin:latest
    container_name: phpmyadmin
    restart: always
    depends_on:
      - db
    ports:
      - 8081:80
    environment:
      PMA_HOST: db
    networks:
      - dev

  apache:
    build: php
    container_name: prestashop
    ports:
      - 8080:80
    volumes:
      - ./php/vhosts:/etc/apache2/sites-enabled
      - ./:/var/www/html
    restart: always
    networks:
      - dev

networks:
  dev:

volumes:
  db-data:

Dockerfile :

FROM php:7.4-apache

RUN echo "ServerName localhost" >> /etc/apache2/apache2.conf

RUN apt-get update 
    && apt-get install -y --no-install-recommends locales apt-utils git libicu-dev g++ libpng-dev libxml2-dev libzip-dev libonig-dev libxslt-dev;

RUN echo "en_US.UTF8 UTF8" > /etc/locale.gen && 
    echo "fr_FR.UTF-8 UTF-8" >> /etc/locale.gen && 
    locale-gen

RUN curl -sSk https://getcomposer.org/installer | php -- --disable-tls && 
    mv composer.phar /usr/local/bin/composer

RUN docker-php-ext-configure intl
RUN docker-php-ext-install pdo pdo_mysql gd opcache intl zip calendar dom mbstring zip gd xsl
RUN pecl install apcu && docker-php-ext-enable apcu
RUN a2enmod rewrite && service apache2 restart
RUN chown -R www-data:w

Output for docker images :

REPOSITORY          TAG          IMAGE ID       CREATED       SIZE
prestadock_apache   latest       740c640530f3   2 days ago    657MB
phpmyadmin          latest       f7fd780fedba   7 days ago    469MB
php                 7.4-apache   899ab23566b7   7 days ago    414MB
mysql               latest       c8562eaf9d81   10 days ago   546MB

Output for docker network ls

NETWORK ID     NAME             DRIVER    SCOPE
e03870bf5fec   bridge           bridge    local
63cfaacfbb2e   chronopiles      bridge    local
c23a0b85edb9   host             host      local
1ae1b68b12c0   none             null      local
1e8010db79e3   prestadock_dev   bridge    local
590b5e949037   prestashop       bridge    local
question from:https://stackoverflow.com/questions/65951412/docker-working-on-localhost-but-have-an-empty-containers-running-list

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The easier approach is pushing your images to the docker hub and just copying yml file to another pc and run docker-compose up command. To achieve this you have to add imagename with your docker hub user name like this:

version: "3.8"
 services:
  db:
    image: mysql:latest
    command: --default-authentication-plugin=mysql_native_password
    container_name: db
    restart: always
    volumes:
      - db-data:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=root
    networks:
      - dev

  phpmyadmin:
    image: phpmyadmin:latest
    container_name: phpmyadmin
    restart: always
    depends_on:
      - db
    ports:
      - 8081:80
    environment:
      PMA_HOST: db
    networks:
      - dev

  apache:
    build: php
    image: benju1/prestashop
    container_name: prestashop
    ports:
      - 8080:80
    volumes:
      - ./php/vhosts:/etc/apache2/sites-enabled
      - ./:/var/www/html
    restart: always
    networks:
      - dev

networks:
  dev:

volumes:
  db-data:

To push the docker images to docker hub follow this command instruction by opening shell or commandline in the folder of docker-compose.yml file

  • Type docker login and enter
  • Enter your docker hub credentials to login
  • type docker-compose build . and enter to build your images
  • type docker-compose push and enter to push the images in your dockerhub

then copy your docker-compose.yml file in your other computer and just type docker-compose up -d to run your project.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...