Toggle navigation
Toggle navigation
This project
Loading...
Sign in
정민우
/
vps_service
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
정민우
2021-06-11 04:20:09 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
a90b912efbd639f0aae906e675fe730f0529a239
a90b912e
1 parent
23c38700
[Add] Container create 추가
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
5 deletions
backend/controllers/dockerController.js
backend/controllers/dockerController.js
View file @
a90b912
...
...
@@ -256,7 +256,46 @@ exports.listContainer = async (req, res) => {
}
exports
.
createContainer
=
async
(
req
,
res
)
=>
{
const
requiredKey
=
[
'id'
]
const
required
=
checkRequiredExist
(
req
.
body
,
requiredKey
)
if
(
required
)
{
logging
(
'container'
,
'error'
,
{
code
:
400
,
message
:
'missingKey:${required}'
},
req
)
return
sendError
(
res
,
400
,
`missingKey:
${
required
}
`
)
}
try
{
const
imageId
=
req
.
body
.
id
let
image
=
await
Image
.
findByPk
(
imageId
)
if
(
!
image
)
{
logging
(
'container'
,
'error'
,
{
code
:
404
,
message
:
'NoImageFound'
},
req
)
return
sendError
(
res
,
404
,
'NoImageFound'
)
}
docker
.
createContainer
({
Image
:
image
.
name
,
Cmd
:
[
'CMD tail -f /dev/null'
],
HostConfig
:
{
Privileged
:
true
}
},
function
(
err
,
container
)
{
container
.
attach
({
stream
:
true
,
stdout
:
true
,
stderr
:
true
,
tty
:
true
},
function
(
err
,
stream
)
{
if
(
err
)
return
sendError
(
res
,
500
,
err
.
message
);
stream
.
pipe
(
process
.
stdout
);
container
.
start
(
function
(
err
,
data
)
{
if
(
err
)
return
sendError
(
res
,
500
,
err
.
message
);
else
return
sendResponse
(
res
,
data
,
200
)
});
});
});
}
catch
(
error
)
{
logging
(
'container'
,
'error'
,
{
code
:
500
,
message
:
error
.
message
},
req
)
return
sendError
(
res
,
500
,
error
.
message
)
}
}
exports
.
startContainer
=
async
(
req
,
res
)
=>
{
...
...
@@ -268,7 +307,7 @@ exports.startContainer = async (req, res) => {
}
try
{
const
containerId
=
req
.
body
.
id
let
container
=
await
Image
.
findByPk
(
containerId
)
let
container
=
await
Container
.
findByPk
(
containerId
)
if
(
!
container
)
{
logging
(
'container'
,
'error'
,
{
code
:
404
,
message
:
'NoContainerFound'
},
req
)
return
sendError
(
res
,
404
,
'NoContainerFound'
)
...
...
@@ -296,7 +335,7 @@ exports.stopContainer = async (req, res) => {
}
try
{
const
containerId
=
req
.
body
.
id
let
container
=
await
Image
.
findByPk
(
containerId
)
let
container
=
await
Container
.
findByPk
(
containerId
)
if
(
!
container
)
{
logging
(
'container'
,
'error'
,
{
code
:
404
,
message
:
'NoContainerFound'
},
req
)
return
sendError
(
res
,
404
,
'NoContainerFound'
)
...
...
@@ -326,7 +365,7 @@ exports.removeContainer = async (req, res) => {
const
user
=
await
currentUser
(
req
.
headers
.
authorization
)
const
containerId
=
req
.
body
.
id
let
container
=
await
Image
.
findByPk
(
containerId
)
let
container
=
await
Container
.
findByPk
(
containerId
)
if
(
!
container
)
{
logging
(
'container'
,
'error'
,
{
code
:
404
,
message
:
'NoContainerFound'
},
req
)
return
sendError
(
res
,
404
,
'NoContainerFound'
)
...
...
@@ -471,7 +510,7 @@ exports.adminDeleteContainer = async (req, res) => {
}
try
{
const
containerId
=
req
.
body
.
id
let
container
=
await
Image
.
findByPk
(
containerId
)
let
container
=
await
Container
.
findByPk
(
containerId
)
if
(
!
container
)
{
logging
(
'container'
,
'error'
,
{
code
:
404
,
message
:
'NoContainerFound'
},
req
)
return
sendError
(
res
,
404
,
'NoContainerFound'
)
...
...
Please
register
or
login
to post a comment