i'm new to docker. I run docker "natively" from a Windows server 2016 with a Windows container, there is no intermediate VM (no docker machine) in between and no docker toolbox, so the "host" is the actual Windows Server that I run docker on.
Docker version:
PS C:> docker version
Client:
Version: 17.03.1-ee-3
API version: 1.27
Go version: go1.7.5
Git commit: 3fcee33
Built: Thu Mar 30 19:31:22 2017
OS/Arch: windows/amd64
Server:
Version: 17.03.1-ee-3
API version: 1.27 (minimum version 1.24)
Go version: go1.7.5
Git commit: 3fcee33
Built: Thu Mar 30 19:31:22 2017
OS/Arch: windows/amd64
Experimental: false
PS C:>
i pulled the image from docker hub. I need to replace the files inside the docker image while running and commit changes to the image.
Lets say i have Sample.java and datafile.properties inside the docker image which i pulled from docker hub.
i want to replace that with Hello.java and data.properties[ i pulled these files from github]
how would i do that in an automated way? Any advise and some examples on this would he helpful. Thanks in advance.
The best way to build an image automated, is to use a Dockerfile. Some information can be found in the documentation, for example; https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/
If you have your Hello.java and datafile.properties in a directory, create a Dockerfile in the same directory, e.g.;
FROM the-base-image-on-docker-hub
RUN rm /path/to/Sample.java
COPY ./Hello.java /path/to/
COPY ./datafile.properties /path/to/
You can then build your image, and "tag" it as myimage:latest with;
docker image build -t myimage:latest .
(the period at the end (.) indicates; use the current directory as "build context" - the build context is uploaded to the docker daemon, and everything in it will be accessible to add to your docker image using the COPY or ADD Dockerfile instructions)
This is a very naive example, just to illustrate the concept; I suggest reading the documentation, to understand the concept, and searching for more examples.
Related
I have a VPS running Windows Server 2022, and I installed docker on it. I am trying to run a container which uses the postgres:14 docker image. But every time I try to run it I get:
no matching manifest for windows/amd64. As far as I understand this is a matching error of sorts where docker is trying to get the postgres image which supports the architecture of the host. Is there any fix for this or should I try another database technology?
Is there a way to set the stack name when using docker-compose?
Currently it takes the folder name (which is a horrible area) and that leads to some confusion.
For example, we have several projects that have a database folder that contains the database stack. When running these on a single host, we have now several database stacks.
There are several ways to do it:
1. Using --project-name (or -p) option when calling docker-compose:
docker-compose -p "my-app" up
Caution: -p "my-app" must come before up.
2. COMPOSE_PROJECT_NAME environment variable:
export COMPOSE_PROJECT_NAME=my-app
docker-compose up
3. COMPOSE_PROJECT_NAME in .env file
Create a file named .env in the project root and set the COMPOSE_PROJECT_NAME environment variable there:
COMPOSE_PROJECT_NAME=some_app
and then:
docker-compose up
The .env file is read from the folder where the docker-compose command
is executed, NOT from the folder of the docker-compose.yml file.
Assuming the following project structure:
root
- database
- docker-compose.yml
- .env
- app
- docker-compose.yml
- .env
- ...
The command below, executed in the root folder, will not give desired effects:
# Stack name 'database' (the folder name). The root/database/.env file not read.
docker-compose -f ./database/docker-compose.yml up
The docker-compose command needs to be executed in the root/database folder:
# Stack name from the root/database/.env
cd database
docker-compose up
If you use option 2 or 3, the project name is applied to all docker-compose commands, as if it were specified with the -p option.
It looks like the project name can be set using the name top level element in the docker-compose file as described here: https://docs.docker.com/compose/compose-file/#name-top-level-element
Top-level name property is defined by the specification as project name to be used if user doesn’t set one explicitly. Compose implementations MUST offer a way for user to override this name, and SHOULD define a mechanism to compute a default project name, to be used if the top-level name element is not set.
This doesn't seem to be well documented anywhere else, and I didn't see a reference to it in the spec changelog, so I'm not sure if this has always been part of the spec, or if compose just didn't support it until recently.
Example
My current directory (pwd):
/Users/brahmlower/development/compose-test
My compose file (cat docker-compose.yml):
version: "3.8"
name: my-project
services:
hello-world:
image: "hello-world:latest"
Without the name property, we would expect to see the stack started with the prefix compose-test since that's the name of the directory. However when I bring the stack up, we see compose names the stack my-project as expected.
The stack output (docker compose up -d):
[+] Running 2/2
⠿ Network my-project_default Created
⠿ Container my-project-hello-world-1 Started
Versions
In case it's helpful, my docker versions are:
compose (docker compose version):
Docker Compose version v2.10.2
docker (docker version):
Client:
Cloud integration: v1.0.29
Version: 20.10.17
API version: 1.41
Go version: go1.17.11
Git commit: 100c701
Built: Mon Jun 6 23:04:45 2022
OS/Arch: darwin/arm64
Context: default
Experimental: true
Server: Docker Desktop 4.12.0 (85629)
Engine:
Version: 20.10.17
API version: 1.41 (minimum version 1.12)
Go version: go1.17.11
Git commit: a89b842
Built: Mon Jun 6 23:01:01 2022
OS/Arch: linux/arm64
Experimental: false
containerd:
Version: 1.6.8
GitCommit: 9cd3357b7fd7218e4aec3eae239db1f68a5a6ec6
runc:
Version: 1.1.4
GitCommit: v1.1.4-0-g5fd4c4d
docker-init:
Version: 0.19.0
GitCommit: de40ad0
I found such command as docker-compose down on docker website, but when I try to use it i get an error.
No such command: down
Commands:
build Build or rebuild services
help Get help on a command
kill Kill containers
logs View output from containers
port Print the public port for a port binding
ps List containers
pull Pulls service images
restart Restart services
rm Remove stopped containers
run Run a one-off command
scale Set number of containers for a service
start Start services
stop Stop services
up Create and start containers
migrate-to-labels Recreate containers to add labels
My docker-compose version is:
docker-compose version: 1.3.1
CPython version: 2.7.10
OpenSSL version: OpenSSL 1.0.2d 9 Jul 2015
Did I do something wrong?
It might be that docker-compose down command is not available in the version you use - the command was added in version 1.6.0 - see the CHANGELOG here.
So if you really want to use the command, you may have to upgrade to version 1.6.0 or later.
Hope this helps.
I'm new to docker and I'm trying to run a postgres database docker with the following command :
docker run --name rva-db -e POSTGRES_PASSWORD=rva -e POSTGRES_DB=rva-db -d postgres -p 5432:5432
If I'm trying to run it without the -p option, it seems to work fine, but I can't reach it from my local pg-admin, I thought I need to add the port link to reach it.
Anyway, the container always crash after few seconds and when i'm trying to start it with the start command I'm getting the following return :
docker start -a rva-db
FATAL: invalid value for parameter "port": "5432:5432"
What did I miss ?
FYI, I'm running it on a MacOS with the following docker version :
$ docker version
Client:
Version: 1.12.1
API version: 1.24
Go version: go1.7.1
Git commit: 6f9534c
Built: Thu Sep 8 10:31:18 2016
OS/Arch: darwin/amd64
Server:
Version: 1.12.1
API version: 1.24
Go version: go1.6.3
Git commit: 23cf638
Built: Thu Aug 18 17:52:38 2016
OS/Arch: linux/amd64
Run the container typing -p option before the image name
docker run --name rva-db -e POSTGRES_PASSWORD=rva -e POSTGRES_DB=rva-db -d -p 5432:5432 postgres
As for Docker run reference docker run has this format
docker run [OPTIONS] IMAGE[:TAG|#DIGEST] [COMMAND] [ARG...]
Options must be before image name. After that you can set entrypoint or command (when theyy differ from default from Dockerfile) and their arguments.
M'm having an issue with a growing data file that is getting too large in my centos7 server. Links to similar issues i've seen: https://github.com/docker/docker/issues/3182
This link suggests stopping docker, deleting the data file and turning back on docker: Why is docker image eating up my disk space that is not used by docker
Will deleting the data loop file destroy my existing container data? Or images? What does this file do?
I can also add more diskspace to this server, but it seems like padding the issue instead of solving whats going on:
Docker Version:
Client version: 1.4.1
Client API version: 1.16
Go version (client): go1.3.3
Git commit (client): 5bc2ff8
OS/Arch (client): linux/amd64
Server version: 1.4.1
Server API version: 1.16
Go version (server): go1.3.3