我是 docker 世界的新手。我想将一些软件包安装到 docker 镜像中。所以我采用了 Ubuntu:14.04 docker 镜像并在那里安装了 MySQL 服务器。然后用它做了一些工作。一旦我退出 docker image 并提交它。但是一旦我启动了 docker 容器,创建的数据库就消失了。这是什么原因?
我使用官方节点映像创建了一个Docker容器。
docker pull node
Run Code Online (Sandbox Code Playgroud)
然后我使用angular-cli创建了一个angular 2应用。
ng new docker-demo
Run Code Online (Sandbox Code Playgroud)
然后我使用以下命令从我的angular2应用程序的目录中运行我的docker容器:
cd docker-demo
Run Code Online (Sandbox Code Playgroud)
&然后在目录中:
docker run -p 8080:4200 -v $(pwd):/var/www -w "/var/www" node npm start
Run Code Online (Sandbox Code Playgroud)
其中pwd代表我的angular2应用程序的目录。
现在,在控制台中,我可以看到我的angular2应用程序已捆绑并正在运行,就像它在本地计算机上运行一样。
但是当我尝试使用docker-machine的ip从浏览器访问它时:
http://192.168.99.100:8080/
Run Code Online (Sandbox Code Playgroud)
它不起作用。
PS:angular2应用程序在我的本地系统上运行良好。
是否需要任何额外的配置?
有输入吗?
提前致谢。
Using this tutorial https://semaphoreci.com/community/tutorials/dockerizing-a-python-django-web-application, I'm dockering my Django application in a VirtualBox using docker-machine. Everything has gone splendidly until I go to my browser and my application says that it's having issues with MySQL.
Then i found this documentation for dockerizing an instance of mysql https://github.com/mysql/mysql-docker which I followed, creating the image in the same development VirtualBox that I created. The error I was originally getting was
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'
Run Code Online (Sandbox Code Playgroud)
My Django …
My environment:
Ubunut 17.04 LTS
npm --version: 5.6.0
nodejs --version: 4.7.2
angular cli version: 1.6.4
Run Code Online (Sandbox Code Playgroud)
docker-compose文件:
version: '3'
services:
my-app:
build:
context: .
dockerfile: Dockerfile
restart: unless-stopped
volumes:
- .:/usr/src/app
ports:
- "4200:4200"
Run Code Online (Sandbox Code Playgroud)
我在dockerfile中注释掉了EXPOSE 4200,因为我已经从docker-compose.yml文件中安装了它,是不是没问题,我应该在dockerfile中公开并在docker-compose中挂载?
在命令行上运行npm start会在浏览器上成功启动应用程序,因为我可以去localhost:4200看看应用程序是否正在运行.
但是,如果我使用docker构建我的应用程序并运行docker-compose,我看到nodejs服务器仍在运行localhost:4200,但是,我无法访问该应用程序,因此localhost:4200无法启动该页面.
运行APP手动工作很棒,我可以在浏览器上看到它:
ubuntu17@ubuntu17:~/playground/apps/myapp-ui$ ng serve
** NG Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
Date: 2018-01-16T16:22:51.912Z
Hash: 40ac2bd0588ee2136d15
Time: 13963ms
chunk {inline} inline.bundle.js (inline) 5.79 kB [entry] [rendered]
chunk {main} main.bundle.js …Run Code Online (Sandbox Code Playgroud) docker dockerfile docker-compose docker-swarm docker-machine
我在互联网上阅读了大量资源,但没有明确指出这一点。有人可以澄清 docker 容器在启动时是否从主机选择时间和时区吗?
我正在尝试在 docker 上设置一主一从和一哨兵,为此我编写了这个 docker compose 文件。
version: '3'
services:
redis-master:
container_name: "redis-master"
image: redis
ports:
- "6379:6379"
command: "redis-server /etc/redis.conf"
volumes:
- "./data/master:/data/"
- "./master.conf:/etc/redis.conf"
redis-slave:
container_name: "redis-slave"
image: redis
ports:
- "6380:6379"
command: "redis-server /etc/redis.conf"
volumes:
- "./data/slave:/data/"
- "./slave.conf:/etc/redis.conf"
depends_on:
- redis-master
redis-sentinel:
container_name: 'redis-sentinel'
image: redis
ports:
- "26379:26379"
command: >
bash -c "chmod 777 /etc/sentinel.conf
&& redis-server /etc/sentinel.conf --sentinel"
volumes:
- "./sentinel.conf:/etc/sentinel.conf"
depends_on:
- redis-master
- redis-slave
Run Code Online (Sandbox Code Playgroud)
sudo docker-compose up --build --force但是,当我尝试使用除 redis-sentinel 之外的所有服务构建它时,所有服务都运行良好。我在日志中收到此错误
redis-sentinel …Run Code Online (Sandbox Code Playgroud) 这个作品
要创建docker卷而不指定磁盘大小:
docker volume create disk1
Run Code Online (Sandbox Code Playgroud)
将卷(disk1)安装到容器
docker run -itd -v disk1:/data ubuntu
Run Code Online (Sandbox Code Playgroud)
这不起作用
现在通过指定100mb的大小来创建docker卷
docker volume create --name disk2 --opt o=size=100m
Run Code Online (Sandbox Code Playgroud)
将卷(大小为100 MB的disk2)安装到容器上
docker run -itd -v disk2:/data ubuntu
Run Code Online (Sandbox Code Playgroud)
当我运行这些命令时,出现以下错误
docker:来自守护程序的错误响应:装载卷'/ var / lib / docker / volumes / disk2 / _data'时出错:卷选项中缺少设备。
docker ×7
dockerfile ×2
mysql ×2
angular ×1
angular-cli ×1
django ×1
docker-swarm ×1
python ×1
redis ×1